2014-11-16 7 views

답변

-1

당신은 FileChannel truncate 사용할 수 있습니다

try { 
    File file = new File("fileToTruncate"); 
    FileChannel fileChannel = new FileOutputStream(file, true).getChannel(); 
    fileChannel.truncate(fileChannel.size() - 1); //Removes last character 
    fileChannel.close(); 
} 
catch (FileNotFoundException ex) { 

} 
catch (IOException ex) { 

} 
+0

전체 파일을 메모리로 읽어들이는 것은 그리 효율적이지 않습니다. 파일 크기가 말하자면 1GB라면? 코드는 기능적으로 정확하지만 시스템에 대한 중요한 요구 사항을 나타냅니다. – VGR

+0

@VGR 감사합니다. 편집 됨. – badjr