Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用java将中文文件源复制到目标_Java - Fatal编程技术网

用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()

使用此代码在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.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方法之一。他们为您的文件创建了一个二进制副本。

这里已经讨论过了-您能给我举个例子吗。但是这个函数可以将中文转换为。它只是将源文件复制到目标文件夹。。。我没有试着用中文文本。。我认为应该行得通。。