-:=编辑简化=:-
在将代码从Linux(Ubuntu LTS 12.4)环境移植到Windows Server 2008的过程中,我遇到一个问题。
我需要使用内存映射文件,但无法在Windows上防止以下错误。
在下面的单元测试中重现了此问题。这两个测试在Linux上均成功完成,但是在Windows上,测试 testWithRandowmAccessFile
失败,并且堆栈跟踪位于底部。 testWithRandowmAccessFile 测试失败
的根本原因是什么? 我应该如何在Windows上实现它? ****
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
public class TestIOOnWindows {
@Test
public void testWithRandowmAccessFile() throws IOException {
final File sourceFile = new File("source.txt");
final File manipulatedFile = new File("manipulated.txt");
final File targetFile = new File("target.txt");
try
(
FileInputStream sourceInputStrea