简体   繁体   English

如何将输入数据从一个文件复制到另一个文件? 在 java

[英]how to copy input data from one file to another one? in java

I have a class called CopyFile.java that has a method with the name copyingFile() that takes in two strings-(String userInfo, String outputfile).我有一个名为CopyFile.java的 class,它有一个名为copyingFile()的方法,它接受两个字符串(字符串 userInfo,字符串输出文件)。 The first argument is for the user info filename and the second argument is for the output filename.第一个参数用于用户信息文件名,第二个参数用于 output 文件名。 The user input data from the first text file is to be copied to the second file as output.第一个文本文件中的用户输入数据将被复制到第二个文件中,即 output。 I was trying to do this but think I went off on the wrong road lol [here is an image of what I have so far which is probably all wrong我试图这样做,但认为我走错了路哈哈[这是我到目前为止所拥有的图像,这可能都是错误的

在此处输入图像描述

You should not do anything with that scanner and user , just write line to the new file.您不应该对该扫描仪和user做任何事情,只需将line写入新文件即可。
Something like:就像是: I hope you also see why it's better to provide code as text and not as picture.我希望您也明白为什么以文本而不是图片的形式提供代码会更好。
If linebreaks disappear (they probably will), add a bufferedWriter.newLine();如果换行符消失(他们可能会),添加一个bufferedWriter.newLine(); into the loop, I did not try the code for obvious reasons.进入循环,我没有尝试代码,原因很明显。

EDIT: you should supply actual filenames when calling copyFile() (not just empty strings) and they should be different.编辑:您应该在调用copyFile()时提供实际的文件名(不仅仅是空字符串),它们应该是不同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM