Reputation: 26192
I'm trying to copy a 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.
Upvotes: 2
Views: 1141
Reputation: 728
If you write the 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.
Upvotes: 4
Reputation: 2022
First, it seems you forgot to close the parenthesis containing the method's arguments.
Second, are you sure getOutputFile() yields a complete file?
Upvotes: 1
Reputation: 6581
Perhaps you need to do a simple test using a debug or sleep:
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).
Upvotes: 1
Reputation: 7078
Try new File(Result,"final_result.txt");
Result should be of type File
and final_result.txt String
Upvotes: 1