반응형
오래된 데이터를 잃지 않고 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
반응형
'programing' 카테고리의 다른 글
여러 Java 프로그램이 동일한 기계에서 실행되는 경우 (0) | 2022.11.03 |
---|---|
모든 JVM 플래그 인쇄 (0) | 2022.11.03 |
캐시 회선 크기에 맞게 조정하는 방법 및 시기 (0) | 2022.11.03 |
AWS 람다:작업 시간 초과 (0) | 2022.11.03 |
Carbon을 사용하여 다른 시간대에서 UTC 가져오기 (0) | 2022.11.03 |