System.out.println("Hello, World");


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileReaderWriterTest{
		public static void main(String[] args) {
			FileReader fr = null;
			FileWriter fw = null;
			//d:\news.txt를 읽어서 news2.txt로 쓴다 char[]로 받아서 쓰이게 된당
			try{
				fr = new FileReader("D:\\news.txt");
				fw = new FileWriter("D:\\news2.txt");
				long l1 = System.currentTimeMillis();
				char[] data = new char[100];
				int length = fr.read(data);
				int count=0;
				
				while(length !=-1){
					fw.write(data,0,length);
					length = fr.read(data);
					count++;
				}
				long l2 = System.currentTimeMillis();
				System.out.println(l2-l1);
				System.out.println(count);					
				
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}finally{
				if(fr!=null){//만약 fi가 null이 아닐 경우
					try {
						fr.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				if(fw!=null){
					try {
						fw.close();
					} catch (IOException e) {
						e.printStackTrace();
						}
					}
				}	
			}
		}

Posted by 김마농