在Intellij IDEA,如何在Eclipseby Ctrl+ H命令中搜索所有项目文件中的字符串或关键字?
我有一个字符串"1427241600000",我希望它转换为"yyyy-MM-dd"格式.
我试过,但我无法解析它,请查看下面的代码
try {
String str = "1427241600000";
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Date date =sf.parse(str);
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我想知道我哪里出错了.
我正在尝试使用 spring 执行“WatchService”,但它看起来不可能,因为当我尝试在应用程序上下文时运行此服务但在控制到来时加载 spring 上下文变得停止
key = watcher.take();
Run Code Online (Sandbox Code Playgroud)
由于这种应用程序上下文的加载没有发生。
下面是完整的代码
@Component
public class DirectoryWatchDemo {
@PostConstruct
public static void test(){
try {
WatchService watcher = FileSystems.getDefault().newWatchService();
Path dir = Paths.get("C:/test");
dir.register(watcher, ENTRY_CREATE);
System.out.println("Watch Service registered for dir: " + dir.getFileName());
while (true) {
WatchKey key;
try {
key = watcher.take();
} catch (InterruptedException ex) {
return;
}
for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
@SuppressWarnings("unchecked")
WatchEvent<Path> ev = (WatchEvent<Path>) event;
Path fileName = ev.context();
System.out.println(kind.name() + ": …Run Code Online (Sandbox Code Playgroud) 请参考以下代码
String line = "abc_dfgb_tf";
String pattern1 = "(\\w+)([+-])(\\d+)(\\w+)";
Pattern r1 = Pattern.compile(pattern1);
Matcher m1 = r1.matcher(line);
if (m1.find( ))
{
System.out.println("Found value: " + m1.group(1) );
System.out.println("Found value: " + m1.group(2) );
System.out.println("Found value: " + m1.group(3) );
System.out.println("Found value: " + m1.group(4) );
}
Run Code Online (Sandbox Code Playgroud)
如果是"abc_dfgb_tf",则字符串m1.find()将变为false.
请建议用于两种类型的字符串"abc_dfgb_tf"和"abc_dfgb_tf + 1cbv"的模式
救命