Advertisement
kijato

LineByLine

Feb 12th, 2020
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.io.*;
  2. import java.nio.*;
  3. import java.util.*;
  4.  
  5. public class LineByLine
  6. {
  7.     public static void main(String[] args) throws IOException, InterruptedException {
  8.         String filename="c:\\Temp\\terkepek\\20180824.dat";
  9.         System.out.println(filename);
  10.         withString(filename);
  11.         //System.out.println("ENTER..."); try { System.in.read(); } catch (Exception e) { e.printStackTrace(); }
  12.         Thread.sleep(5000);
  13.         withStringBuffer(filename);
  14.         //System.out.println("ENTER..."); try { System.in.read(); } catch (Exception e) { e.printStackTrace(); }
  15.         Thread.sleep(5000);
  16.     }
  17.  
  18.     private static void withString(String filename) {
  19.         try {
  20.             BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
  21.             String line = null;
  22.             while ( ( line = br.readLine() ) != null ) {
  23.                 //System.out.println(line);
  24.             }
  25.         } catch (Exception e) {
  26.         }
  27.     }
  28.  
  29.     private static void withStringBuffer(String filename) {
  30.         try {
  31.             BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
  32.             StringBuilder line = new StringBuilder();
  33.             while ( ( line.replace(0, line.length(), br.readLine().replaceAll("\\s*\\*\\s*$","") ) ) != null ) {
  34.                 //System.out.println(line.toString());
  35.             }
  36.         } catch (Exception e) {
  37.         }
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement