作者god800606 (還沒想到)
看板java
標題[問題] 關於用FileChannel 分割檔案
時間Wed Aug 10 15:46:47 2011
各位大家好
最近剛學到用FileChannel 來分割檔案
主要code 如下
for ( int i = 1; i <= tmpFileCount+1; i++ ) {
FileChannel fout = new
FileOutputStream(tmpFilePath(i)).getChannel();
long notTransferredSize = sourceFileSize - perTmpFileSize;
boolean finalLoop = notTransferredSize < perTmpFileSize;
if ( finalLoop ) {
fin.transferTo(transferredSize, notTransferredSize, fout);
} else {
fin.transferTo(transferredSize, perTmpFileSize, fout);
transferredSize += perTmpFileSize;
}
fout.close();
}
fin.close();
System.out.println("Sperate done");
如果我想要在每個分割後的檔案最後面 加一個換行('\n')
也就是說不要讓原本的最後一行 最後面沒有'\n'
我該怎麼做呢? 是不是FileChannel 不能用 .write ?
謝謝各位大大 <(_ _)>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.23.86.187
→ pico2k:請先查一下Javadoc,好嗎? 08/10 16:10
→ god800606:恩~ 好 08/10 16:12
→ god800606:可以用write(ByteBuffer) 不過 putChar 後還是沒有ㄟ? 08/10 16:43
→ god800606:buf.put((byte)'\n'); 我是這樣寫 可以嗎? 08/10 17:36
→ god800606:解決囉 謝謝P大 ~~! 08/11 09:27