JAVA
자바 파일 입출력2
Reubwe
2012. 3. 30. 01:18
출처 : http://joongang.springnote.com/pages/4642959.xhtml
- import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException; - public class FileIOEx5 {
- public static void main(String[] args)
{
FileReader fr = null; // 파일로 부터 텍스트 데이터를 읽는데 사용함.
int c1;
int c2;
int c3;
try {
fr = new FileReader("c:\\test.txt");
// c1 = fr.read();
// c2 = fr.read();
// c3 = fr.read();
//
// System.out.println((char)c1);
// System.out.println((char)c2);
// System.out.println((char)c3);
int c =0;
while((c = fr.read()) != -1)
{
System.out.print((char)c); // 한글자씩 읽어서 출력하고 끝까지 읽음.(-1) - // test.txt파일에서 하나씩 출력하고 콘솔에 나타내고 끝까지 읽음.
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if(fr != null) try{ fr.close(); } catch(IOException e) {}
}
}
}