相关疑难解决方法(0)

用Java读取纯文本文件

似乎有不同的方法来读取和写入Java中的文件数据.

我想从文件中读取ASCII数据.可能的方式和差异是什么?

java file-io ascii

908
推荐指数
16
解决办法
229万
查看次数

扫描仪与BufferedReader

据我所知,从Java文件中读取基于字符的数据的两种最常用的方法是使用ScannerBufferedReader.我也知道BufferedReader通过使用缓冲区来有效地读取文件以避免物理磁盘操作.我的问题是:

  • 是否Scanner执行以及BufferedReader
  • 你为什么选择Scanner,BufferedReader反之亦然?

java file-io bufferedreader java.util.scanner

267
推荐指数
8
解决办法
25万
查看次数

快速CSV解析

我有一个java服务器应用程序,下载CSV文件并解析它.解析可能需要5到45分钟,并且每小时发生一次.这种方法是应用程序的瓶颈,因此它不是过早的优化.到目前为止的代码:

        client.executeMethod(method);
        InputStream in = method.getResponseBodyAsStream(); // this is http stream

        String line;
        String[] record;

        reader = new BufferedReader(new InputStreamReader(in), 65536);

        try {
            // read the header line
            line = reader.readLine();
            // some code
            while ((line = reader.readLine()) != null) {
                 // more code

                 line = line.replaceAll("\"\"", "\"NULL\"");

                 // Now remove all of the quotes
                 line = line.replaceAll("\"", "");     


                 if (!line.startsWith("ERROR"){
                   //bla bla 
                    continue;
                 }

                 record = line.split(",");
                 //more error handling
                 // build the object and put it in HashMap …
Run Code Online (Sandbox Code Playgroud)

java csv parsing

15
推荐指数
4
解决办法
2万
查看次数

标签 统计

java ×3

file-io ×2

ascii ×1

bufferedreader ×1

csv ×1

java.util.scanner ×1

parsing ×1