读取文本文件的内容

时间:2016-02-11 10:27:55

标签: java gwt gwt-highcharts

我正在编写一个显示chrats的应用程序。我正在使用GWT Highcharts(由Moxie Group提供)来显示结果。我在图表中添加了一个随机数,它没有问题。

但我想从文本文件中加载数字。我只是想读取文件的内容并将其放在数组或类似的东西上。我怎么能用Java做到这一点?

1 个答案:

答案 0 :(得分:0)

您可以使用如下所示的小程序来实现:

您可能需要更改逻辑以按照您希望的方式为GWT highcharts读取元素!

NSError *e = nil;
NSString *iso = [[NSString alloc] initWithData:d1 encoding:NSISOLatin1StringEncoding];
NSData *dutf8 = [iso dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:dutf8 options:NSJSONReadingMutableContainers error:&e];

Test.txt文件的内容是这样的:

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();
        }
    }
}
相关问题