代码拉取完成,页面将自动刷新
方法1:
/**
* 打印堆栈 : 获取文件名和当前执行代码的行号
*/
public static void printStack() {
final Throwable t = new Throwable();
StackTraceElement[] frames = t.getStackTrace();
for (StackTraceElement frame : frames) {
System.out.println(frame);
}
}
方法2:
Thread.dumpStack();
方法3:
/**
* 获取当前行堆栈调用信息
*/
public static String getStackString() {
StringWriter out = new StringWriter();
new Throwable().printStackTrace(new PrintWriter(out));
String description = out.toString();
System.out.println(description);
return description;
}
/**
* 带资源的 try 语句
*/
public static void test02() {
//用这种方式,无论如何,in 和 out 都会关闭
try (Scanner in = new Scanner(new FileInputStream("words"), "utf-8");
PrintWriter out = new PrintWriter("out")) {
while (in.hasNext()) {
out.println(in.next().toUpperCase());
}
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。