0%

[Java] Read File

[Jave] Read File

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.io.*;          // this is for IO
import java.util.Scanner; // this is for Scanner

StringBuilder text=new StringBuilder();
// Ref: http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html

String NL=System.getProperty("line.separator"); // Line separator ("\n" on UNIX)
Scanner scanner=new Scanner(new FileInputStream(strFileName));

try{
while(scanner.hasNext()){
text.append(scanner.nextLine()+NL);
}//while
}finally{
scanner.close();
}//try_catch_finally