views:

69

answers:

4

Hello I'm trying to copy file to another directory with commons fileUtils. I tried this

FileUtils.copyFile(getOutputFile(), new File("RESULT/final_result.txt");

The new final_result.txt file contains only the first line of my output file, what did I do wrong?

Is there an alternative to commons IO, or some other way I'll take any as long as it does the trick.

+1  A: 

first, it seems you forgot to close the parenthesis containing the method's arguments. second, are you sure getOutputFile() yields a complete file?

ozk
@ozk I'm sure that name is right and that null pointer is not thrown and that the file is there with many lines, how can I know does getOutputFile yield a complete file?
Gandalf StormCrow
+1  A: 

Try new File(Result,"final_result.txt");
Result should be of type File and final_result.txt String

Zaki
... *still* looks like some quotation marks are missing ...
Andreas_D
@Zaki even if I put just final result .txt without result same thing happens
Gandalf StormCrow
+4  A: 

if you write file (which you get by getOutputFile()) before this operation, be sure to flush() all changes.
Otherwise it seems to be a bug. But it is unlikely.

foret
I flushed the filewritter which is writting into output file if you mean that, what else could I flush?
Gandalf StormCrow
+1  A: 

Perhaps you need to do a simple test using a debug or sleep:

  1. manually delete RESULT/final_result.txt
  2. run the code that creates your output file and either sleep, or use a breakpoint with debugging to stop after the files is created.
  3. Manually open RESULT/final_result.txt and see what's there.
  4. let your program finish it's task.

You'll either find that your write is not complete (in step 3) and you'll need to flush/close the correct ouput stream, or you'll find that the copy is doing something weird (which is less likely).

jowierun