0

copying Chinese file in java using this code . but the destination file contains question mark (?) instead of Chinese character . is there any way in java to achieve this functionality..

 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();
}
Vikram Pareek
  • 21
  • 1
  • 2
  • 4
    Have already been discussed here - http://stackoverflow.com/questions/15377756/write-chinese-characters-from-one-file-to-another –  Dec 14 '15 at 10:42

3 Answers3

0

You are miss the extension of files for ex: file.txt and file2.txt:

   File source = new File("H:\\work-temp\\file.txt");
   File dest = new File("H:\\work-temp\\file2.txt");

For coping use this:

  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();
}

For more info go to this link

Abdelhak
  • 8,299
  • 4
  • 22
  • 36
0

First of all, while copying a file, the destination should be a folder not file... so please change File dest = new File("H:\\work-temp\\file2"); to File dest = new File("H:\\work-temp");

Next you should use FileUtils.copyFile(source, dest); instead FileUtils.copyDirectory(source, dest);

NewBee Developer
  • 432
  • 2
  • 9
  • 26
0

Use one of the JDK 7 Files.copy methods. They create a binary copy of your file.

BetaRide
  • 16,207
  • 29
  • 99
  • 177