programing

오래된 데이터를 잃지 않고 FileOutputStream을 사용하여 데이터를 쓰는 방법

itsource 2022. 11. 3. 22:12
반응형

오래된 데이터를 잃지 않고 FileOutputStream을 사용하여 데이터를 쓰는 방법

를 사용하여 작업하는 경우FileOutputStream메서드, 이 메서드를 사용하여 파일을 쓸 때마다 이전 데이터가 손실됩니다.이전 데이터를 잃지 않고 파일을 쓸 수 있는 방법은FileOutputStream?

다음을 수행하는 생성자를 사용합니다.File및 aboolean

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

반응형