這裏介紹java class tard。我試圖從一個文件讀取數據,然後操縱到一個不同的文件並保存。我認爲我很接近,但有問題一起使用掃描儀和.IO。任何幫助都會很棒。如何從文件讀取數據並將其放入變量並輸出到不同的文件。 Java
import java.util.Scanner;
import java.io.*;
public class fileswitch
{
public static void main(String[] Args) throws IOException
{
String filename;
String filename2;
String text;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the name of a file: ");
filename = keyboard.nextLine();
PrintWriter outputFile = new PrintWriter(filename);
System.out.print("Enter the name of a second file: ");
filename2 = keyboard.nextLine();
PrintWriter outputFile2 = new PrintWriter(filename2);
while (filename.hasNextLine())
{
text = filename.readAllLines();
text = text.toUpperCase();
outputFile2.print(text);
outputFile2.close();
}
}
}
+1很好的例子test.txt文件。 – Brandon