我现在使用java Desktop API来操作文件资源管理器.我知道如何打开文件资源管理器,但我不知道如何打开它并突出显示指定的文件.
当我们使用Chrome时,在下载文件后,我们可以选择"在文件夹中显示"来打开文件资源管理器并突出显示下载的文件.
如何使用java Desktop API这样做?或者java中是否有其他API可以实现此操作?
这次我想从抛出的异常中获取注释.我的示例代码是这样的:
public class P {
@MyAnnotation(stringValue = "FirstType", intValue = 999)
public void test() throws Exception {
// ...
throw new NullPointerException();
}
@MyAnnotation(stringValue = "SecondType", intValue = 111)
public void test(int a) throws Exception {
// ...
throw new NullPointerException();
}
}
Run Code Online (Sandbox Code Playgroud)
上面的类包含2个方法,它们都抛出NullPointerException.
现在我可以使用callerElement来检索异常,并知道导致异常的包名,类名和行号.这是我的代码:
public class CallP {
public static void main(String[] argv){
P class_p = new P();
StackTraceElement[] callerElement = null;
try{
class_p.test();
}catch(Exception e){
callerElement = e.getStackTrace();
System.out.println(callerElement[0].toString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制台窗口中,我可以看到该消息
StackoverflowQuestion.P.test(P.java:9)
我的问题是1.如何在catch子句中获取注释?2.当方法重载时(在P类,我有两个方法叫test),如何获取注释?
这就是我的全部问题.感谢您花时间阅读.
当我们运行我们的构建时,我们发现了以下错误
ERROR in node_modules/@types/ramda/index.d.ts:373:64 - error TS1110: Type expected.
373 (<S1 extends string, S2 extends string>(s1: S1, s2: S2) => `${S1}${S2}`);
Run Code Online (Sandbox Code Playgroud) 当我收到诸如IOException或RunTimeException之类的异常时,我只能知道班级中的行号.
我的第一个问题.是否可以通过异常检索方法名称?第二,是否可以通过行号检索该方法的方法和参数?
ps我需要知道确切的方法名称及其参数,因为我想区分重载方法.为了区分重载方法,我所知道的只是确定其参数.