Java输入/输出文件编码问题

时间:2013-11-29 16:24:02

标签: java file input io output

您好我正在尝试制作一个代码,用于提取用户输入文件,然后将该文件复制到我用全大写字母创建的新文件中。我不知道为什么这不起作用。

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();
    }

}

1 个答案:

答案 0 :(得分:0)

您的代码将原始文件写入Uppercase.txt而不转换为大写。改变

String write = inputFile.nextLine(); 

String write = inputFile.nextLine().toUpperCase();