Java에서 파일에 쓰기 - FileOutputStream

Java에서 바이너리 데이터는 FileOutputStream 쓰기 스트림으로 작성됩니다. 파일에 쓰려면 데이터를 비트로 변환하여 파일에 저장해야 합니다.

 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class WriteFileExample {
public static void main(String[] args) {

FileOutputStream fop = null;
파일 파일;
Content String = "추가된 내용";

try {

file = new File("test.txt");
fop = 새로운 FileOutputStream(파일);

// 파일이 없으면 만듭니다
if (!file.exists()) {
file.createNewFile();
}

// 바이너리로 변환 data
byte[] contentEnBytes = content.getBytes();

fop.write(EnBytes 내용);
fop.flush()를 호출합니다.
fop.close();

System.out.println("편집 완료!");

} catch (IOException e) {
e.printStackTrace();
} 마지막으로 {
시도 {
if (fop != null) {
fop.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
리소스:
http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileOutputStream.html