尝试将文件从一个位置复制到另一个位置
我正在尝试使用 Commons' fileUtils 将文件复制到另一个目录。我尝试了
FileUtils.copyFile(getOutputFile(), new File("RESULT/final_result.txt");
新的 final_result.txt
文件仅包含输出文件的第一行,我做错了什么?
是否有 Commons IO 的替代方案,或者我会采取的其他方式只要它能起到作用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您在此操作之前写入文件(通过 getOutputFile() 获取),请务必刷新()所有更改。
否则它似乎是一个错误。但这不太可能。
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.
尝试
new File(Result,"final_result.txt");
结果应为
File
类型和 Final_result.txtString
Try
new File(Result,"final_result.txt");
Result should be of type
File
and final_result.txtString
也许您需要使用调试或睡眠进行简单的测试:
您要么会发现您的写入未完成(在步骤 3 中),并且您需要刷新/关闭正确的输出流,要么您会发现副本正在执行一些奇怪的操作(这不太可能)。
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).
首先,您似乎忘记关闭包含方法参数的括号。
其次,您确定 getOutputFile() 生成完整的文件吗?
First, it seems you forgot to close the parenthesis containing the method's arguments.
Second, are you sure getOutputFile() yields a complete file?