GGYU

BufferedReader/Writer 사용법 본문

프로그래밍/JAVA

BufferedReader/Writer 사용법

GANADARA 2018. 7. 19. 21:13
  • public class FileTextWriteReadExample {
  •    
  •     public static void main(String[] args){
  •        
  •         File inFile = new File("C:\\Users\\Public""in.txt");
  •         File outFile = new File("C:\\Users\\Public""in.txt");
  •        
  •         //==========================//
  •         // 텍스트 파일 쓰기
  •         //==========================//
  •         BufferedWriter bw = null;
  •         try {
  •             bw = new BufferedWriter(new FileWriter(outFile));
  •             bw.write("테스트 합니다.");
  •             bw.newLine();
  •             bw.write("테스트 합니다.1");
  •             bw.flush();
  •         } catch (IOException e) {
  •             e.printStackTrace();
  •         }finally {
  •             if(bw != null) try {bw.close()} catch (IOException e) {}
  •         }
  •        
  •         //==========================//
  •         // 텍스트 파일 읽기
  •         //==========================//
  •         BufferedReader br = null;
  •         try {
  •             br = new BufferedReader(new FileReader(inFile));
  •             String line;
  •             while ((line = br.readLine()) != null) {
  •                 System.out.println(line);
  •             }
  •         } catch (FileNotFoundException e) {
  •             e.printStackTrace();
  •         } catch (IOException e) {
  •             e.printStackTrace();
  •         }finally {
  •             if(br != null) try {br.close()} catch (IOException e) {}
  •         }
  •     }
  • }

  • '프로그래밍 > JAVA' 카테고리의 다른 글

    thread 사용법  (0) 2018.07.19
    threadpool 사용법  (0) 2018.07.19
    디렉토리 조회  (0) 2018.07.19
    Input/OutputStream  (0) 2018.07.19
    LineNumberReader 사용법  (0) 2018.07.19
    Comments