我收到此错误:
Exception in thread "main" java.lang.IllegalArgumentException
at sun.nio.ch.FileChannelImpl.transferTo<Unknown Source>
at Program.insert<Program.java:14>
at Program.main<Program.java:203>
我唯一能想到的是参数类型不匹配。我检查了传递给方法的类型,它们匹配。将FileChannel传递给方法可能会出现问题吗?我在http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html
的文档中没有看到任何内容以下是相关方法:
public static void insert (RandomAccessFile fileForInsertion, FileChannel srcChannel, FileChannel tgtChannel, long offset, byte[] content) throws FileNotFoundException, IOException
这是方法14中的第14行:
srcChannel.transferTo(offset, (filesize - offset), tgtChannel);
这是对方法的调用,第203行:
insert(rFile, sourceChannel, targetChannel, insertionIndex, textToInsertBytes);
以下是如何创建传递的参数:
RandomAccessFile rFile = new RandomAccessFile(new File(rFileName), "rw");
FileChannel sourceChannel = rFile.getChannel();
FileChannel targetChannel = randomTemp.getChannel();
long insertionIndex = 0;
byte[] textToInsertBytes = new byte[0];
我错过了一些明显的东西吗?当我在各个站点上查看答案时,我注意到一些错误消息给出了一个原因,例如&#34; java.lang.IllegalArgumentException:父路径不能为空。&#34;但是,我的信息并没有。还有什么可能是问题?