如何修改此run方法,不仅可以在输出窗口中打印srting,还可以在项目目录中写入文件,例如outfile.txt.此外,每个字符串应位于文件中的单独行.
所以我已经在项目目录中创建了一个名为outfile.txt的文件
在代码在窗口上打印正常但不在文本文件中打印的那一刻
这是代码#
public void run() throws IOException
{
Scanner sc = new Scanner(System.in);
boolean cont = true;
while (cont) {
System.out.println("Enter text");
String s = sc.nextLine();
if ("*".equals(s)) {
cont = false;
} else {
String result = shorthand(s);
System.out.println(result);
PrintWriter pw = new PrintWriter("outfile.txt");
pw.println(result);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
458 次 |
| 最近记录: |