1 Reply Latest reply: Aug 13, 2010 12:35 AM by EJP RSS

    How to increase speed to read file text ?

    843790
      HI All

      At the currency . I write new application, my application read file text and write to other text file (encode UTF-16) But Speed is very low. (Notes : When Original file have changed, my application read new content of file and write to target file). My source code read file below. Please help me, how to increase speed to read file ?

      public String readLineEncode(int totalLines) throws Exception {
      
                StringBuilder text = new StringBuilder("");
                try {
                     long l = System.currentTimeMillis(), elapsed;
                     int lineRead = 0;
                     long fileLength = 0;
                     String sOutput;
                     File file = new File(filePath);
                     fileLength = file.length();
                     if(skipBytes > fileLength) return text.toString();
                     
                     FileInputStream fis = new FileInputStream(file);
                     BufferedReader buffered = new BufferedReader(new InputStreamReader
                               (fis, AppSystem.CHARSET_NAME_UTF_16));
                     String sStringValueLine = null;
                     l = System.currentTimeMillis();
                     buffered.skip(skipBytes);
                     
                     while( (sStringValueLine = buffered.readLine()) != null &&  lineRead < totalLines) {
                          byte []a = sStringValueLine.getBytes();   
                          text.append(sStringValueLine.trim() + AppSystem.NL);
                          skipBytes += a.length + 2;
                          lineRead++;
                     }
                     buffered.close();
                     
                     
                     if(sStringValueLine == null) this.EOF = true;
      
                     elapsed = (System.currentTimeMillis() - l);
                     sOutput = "Time elapsed read " + lineRead + " line text :: " + elapsed; 
                     AppSystem.outConsole(sOutput);
                } catch (Exception e) {
                     System.out.println(e.toString());
                }
                return text.toString();
      
           }
      }