您好我正在尝试制作一个代码,用于提取用户输入文件,然后将该文件复制到我用全大写字母创建的新文件中。我不知道为什么这不起作用。
import java.util.Scanner;
import java.io.*;
public class playAround {
public static void main(String[] args) throws IOException {
PrintWriter outputFile = new PrintWriter("Uppercase.txt");
Scanner check = new Scanner(System.in);
System.out.println("Enter the filename you would like to be formatted into UPPERCASE");
String filename = check.nextLine();
File file = new File(filename);
Scanner inputFile = new Scanner(file);
while(inputFile.hasNext()){
String write = inputFile.nextLine();
outputFile.println(write.toUpperCase());
}
inputFile.close();
outputFile.close();
}
}
答案 0 :(得分:0)
您的代码将原始文件写入Uppercase.txt
而不转换为大写。改变
String write = inputFile.nextLine();
到
String write = inputFile.nextLine().toUpperCase();