我有上面的代码。我想做的是在一个txt文件中写一个字符串。
import java.io.*;
import java.util.*;
public void writeAsfalizomenos(asfalizomenos myObj) throws IOException {
Scanner scanner = new Scanner(System.in);
System.out.print("Surname: ");
String username = scanner.nextLine();
System.out.println(username);
FileWriter outFile = new FileWriter("asdf.txt", true);
PrintWriter out1 = new PrintWriter(outFile);
out1.append(username);
out1.println();
out1.append("adfdas");
//
// Read string input for username
//
}
public static void main(String [] args) throws IOException{
asfalizomenos a = new asfalizomenos();
a.writeAsfalizomenos(a);
}
上面的代码创建了一个 txt 文件,但它没有将字符串写入其中。关于我的错误的任何想法?