Java
파일읽기 기본
MuGrammer
2013. 12. 31. 15:41
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; /** * @author mugrammer * */ public class FileReader { /** * @param args */ public static void main(String[] args) { String path = args[0]; if(path == null){ return; } File fr = new File(path); String line; try { BufferedReader inFile = new BufferedReader(new InputStreamReader(new FileInputStream(fr), "utf-8")); while ((line = inFile.readLine()) != null) { System.out.println(line); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
반응형