java KeyboardToFile 예제
public static void main(String[] args) throws IOException{ // 1. 입출력 스트림 선언 InputStreamReader isr = new InputStreamReader(System.in); BufferedReader bsr = new BufferedReader(isr);
// 2. 예외처리 try{ //FileWriter fw = new FileWriter(new File(“c:\output.txt”)); FileOutputStream fos = new FileOutputStream(new File(“c:\output.txt”));
// 3. 입출력 스트림 생성
//String text=”dddd”;
//fw.write(text);
//fw.write(bsr.readLine());
//fw.close(); /* while(bsr.readLine()!=null){ fos.write(bsr.readLine().getBytes()); } */ String a = JOptionPane.showInputDialog(“값을 입력하세요”); fos.write(a.getBytes()); fos.flush(); fos.close();
}catch(Exception e){ e.printStackTrace(); }finally{ // 5. 입출력 스트림 닫기
} }
This article is licensed under CC BY 4.0 by the author.