[英]Need to read a text file and write to a new one
So I have this code where it prompts the user to type in a file name for the input file and the file name for the output file. 所以我有这段代码,它提示用户输入输入文件的文件名和输出文件的文件名。 I have a string called 'names' which will then be stored into the input file that was created by the user.
我有一个名为“名称”的字符串,然后将其存储到用户创建的输入文件中。 I've got this part down.
我已经把这一部分讲完了。
import com.sun.org.apache.xpath.internal.SourceTree;
import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
FileWriter writer = new FileWriter(chooseFile("input"));
FileWriter writer2 = new FileWriter(chooseFile("output"));
String separator = String.format("%n");
for(String name: names){
writer.write(name);
writer.write(separator);
}
}
}
public static File chooseFile(String type) {
String fname = null;
}
return file;
}
}
Something like so should modify your names list to all caps. 诸如此类的事情应将您的姓名列表修改为全部大写。
for (int i = 0; i < names.length; i++) {
names[i] = names[i].toUpperCase();
// writer2.write(names[i]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.