![](/img/trans.png)
[英]Android Studio stuck at "Analyzing..." but only when opening Java files
[英]Opening and Analyzing ASCII files
如何打开和读取ASCII文件? 我正在努力打开和检索文件的内容,并使用图形对其进行分析。
基于文本的文件应使用java.io.Reader
打开。 最简单的方法是使用BufferedReader
在循环中逐行读取它。
这是一个启动示例:
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("/path/to/file.txt"));
for (String line; (line = reader.readLine()) != null;) {
// Do your thing with the line. This example is just printing it.
System.out.println(line);
}
} finally {
// Always close resources in finally!
if (reader != null) try { reader.close(); } catch (IOException ignore) {}
}
要使用令牌进一步细分文件内容,您可能会发现Scanner
更有用。
只需通过java.io
方法打开文件。 告诉我们您首先尝试了什么,是吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.