달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2016. 12. 12. 03:59

Java 파일 캐릭터 단위로 쓰기 Basic Languages/Java2016. 12. 12. 03:59

FileWriter는 캐릭터 스트림이다. 2바이트 단위로 쓴다.

(1바이트 단위가 아니다)


public class FileWrite {

public static void fileWrite(){

FileWriter fw = null;

try{

fw = new FileWriter("output.txt");

fw.write((int)'a');

fw.write((int)'b');

fw.write((int)'c');

fw.write("def");

}catch(IOException e){

e.printStackTrace();

}finally{

try{ fw.close(); }catch(IOException e){};

}

}


public static void main(String[] args) {

fileWrite();

}

}

:
Posted by 클레잇