바이트를 temp.fls 파일에 쓰고 있습니다. 작업을 완료 한 후 temp.fls 파일에서 마지막 256 바이트를 삭제하려고합니다. 이것을 어떻게 할 수 있습니까? 도와주세요.Java에서 파일 내용 삭제
미리 감사드립니다. 그래서 같은
바이트를 temp.fls 파일에 쓰고 있습니다. 작업을 완료 한 후 temp.fls 파일에서 마지막 256 바이트를 삭제하려고합니다. 이것을 어떻게 할 수 있습니까? 도와주세요.Java에서 파일 내용 삭제
미리 감사드립니다. 그래서 같은
사용 RandomAccessFile.setLength()
:
RandomAccessFile f = new RandomAccessFile(yourFile,"rw");
f.setLength(f.length()-256);
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class RandomAccessFileDemo {
public static void main(String ... args) throws FileNotFoundException, IOException
{
File file = new File(<FILE_PATH>);
System.err.println("MSR:: RandomAccessFileDemo :: the target length is"+file.length());
RandomAccessFile raf = new RandomAccessFile(file,"rwd");
raf.seek(file.length()-1); // Set the pointer to the end of the file
System.err.println("MSR:: RandomAccessFileDemo :: the file pointer is"+raf.getFilePointer());
raf.setLength(raf.length()-raf.length());
}
}
PLZ 나에게 몇 가지 예제 코드 –
@rekha을 제공 : spdenne는 당신에게 API 문서에 대한 링크를했다. 그것과 건설자를 한번보세요. – boutta