我正在编写一个显示 chrats 的应用程序。我正在使用 GWT Highcharts(由 Moxie Group 提供)来显示结果。我在图表中添加了一个随机数,它可以正常工作。
但我想从文本文件中加载数字。我只想读取文件的内容并将其放在数组或类似的东西上。我怎样才能在 Java 中做到这一点?
我正在编写一个显示 chrats 的应用程序。我正在使用 GWT Highcharts(由 Moxie Group 提供)来显示结果。我在图表中添加了一个随机数,它可以正常工作。
但我想从文本文件中加载数字。我只想读取文件的内容并将其放在数组或类似的东西上。我怎样才能在 Java 中做到这一点?
您可以使用如下所示的小程序来实现:
您可能必须更改逻辑以按照您想要的方式为 GWT 高图读取元素!
public class ReadATextFile {
public static void main(String[] args) {
try (RandomAccessFile readFile = new RandomAccessFile("C:\\Test.txt", "r");) {
int EOF = (int) readFile.length();
System.out.println("Length of the file is (" + EOF + ") bytes");
//Considering to read the first 150 bytes out of 168 bytes on the file
readFile.seek(0);
byte[] bytes = new byte[EOF];
readFile.readFully(bytes);
readFile.close();
System.out.println(new String(bytes));
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
Test.txt 文件的内容是这样的:
1 2 3 4
5 6 7 8
9 10 11