program tip

오래된 데이터를 잃지 않고 FileOutputStream으로 데이터를 쓰는 방법은 무엇입니까?

radiobox 2020. 10. 5. 07:48
반응형

오래된 데이터를 잃지 않고 FileOutputStream으로 데이터를 쓰는 방법은 무엇입니까?


FileOutputStream메서드로 작업하는 경우이 메서드를 통해 파일을 작성할 때마다 이전 데이터가 손실됩니다. 을 통해 이전 데이터를 잃지 않고 파일을 쓸 수 FileOutputStream있습니까?


File및 a 를 취하는 생성자를 사용하십시오 .boolean

FileOutputStream(File file, boolean append) 

부울을 true. 이렇게하면 이미있는 데이터를 덮어 쓰지 않고 작성한 데이터가 파일 끝에 추가됩니다.


생성자를 사용하여 파일에 재료를 추가합니다.

FileOutputStream(File file, boolean append)
Creates a file output stream to write to the file represented by the specified File object.

따라서 파일에 "abc.txt"를 추가하려면

FileOutputStream fos=new FileOutputStream(new File("abc.txt"),true);

참고 URL : https://stackoverflow.com/questions/8544771/how-to-write-data-with-fileoutputstream-without-losing-old-data

반응형