用java将中文文件源复制到目标
使用此代码在java中复制中文文件。但是目标文件包含问号(?)而不是汉字。java中是否有任何方法可以实现此功能用java将中文文件源复制到目标,java,Java,使用此代码在java中复制中文文件。但是目标文件包含问号(?)而不是汉字。java中是否有任何方法可以实现此功能 File source = new File("H:\\work-temp\\file"); File dest = new File("H:\\work-temp\\file2"); try { FileUtils.copyDirectory(source, dest); } catch (IOException e) { e.printStackTrace()
File source = new File("H:\\work-temp\\file");
File dest = new File("H:\\work-temp\\file2");
try {
FileUtils.copyDirectory(source, dest);
} catch (IOException e) {
e.printStackTrace();
}
您缺少文件扩展名,例如:
file.txt
和file2.txt
:
File source = new File("H:\\work-temp\\file.txt");
File dest = new File("H:\\work-temp\\file2.txt");
使用以下方法:
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try{
inputChannel = new FileInputStream(source).getChannel();
outputChannel = new FileOutputStream(dest).getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} finally {
inputChannel.close();
outputChannel.close();
}
有关详细信息,请转到此首先,复制文件时,目标应为文件夹而不是文件。。。因此,请更改
File dest=新文件(“H:\\work temp\\file2”)代码>到文件dest=新文件(“H:\\work temp”)代码>
接下来您应该使用FileUtils.copyFile(source,dest)代码>改为FileUtils.copyDirectory(源,目标)代码>使用JDK 7方法之一。他们为您的文件创建了一个二进制副本。这里已经讨论过了-您能给我举个例子吗。但是这个函数可以将中文转换为。它只是将源文件复制到目标文件夹。。。我没有试着用中文文本。。我认为应该行得通。。