我正在尝试进行类似的工作:
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Scanner;
import static java.lang.System.in;
import static java.lang.System.out;
class PrintWrit1
{
public static void main(String[] args)
{
Scanner input = new Scanner(in);
out.print("Enter the filename :\t");
String filename = input.nextLine();
try( PrintWriter pw = new PrintWriter(filename))
{
out.println("Enter the file content, enter * after finishing");
String text;
while((text=input.nextLine()) != "*")
{ pw.println(text); }
out.println(filename+" is saved and closed");
}
catch(IOException ioe)
{ ioe.printStackTrace();}
}
}
已创建文件,写入了输出,但是保存了文件而不是按ctrl-C时的*,但是随后的语句将不执行,并且会突然终止。
我正在寻找关于此的任何建议,如果我在输入最后一行之后输入*,它应该能够执行out.println(filename+" is saved and closed")
当前输出:
D:\JavaEx\FILE-IO>java PrintWrit1
Enter the filename : sample
Enter the file content, enter * after finishing
line1
line2
*
预期输出:
D:\JavaEx\FILE-IO>java PrintWrit1
Enter the filename : sample
Enter the file content, enter * after finishing
line1
line2
*
sample is saved and closed
答案 0 :(得分:2)
您错误地比较了字符串*。您应该使用from Ipython.display import display,HTML
df_xyz=(...)
display(df)
方法。
请替换
equals()
到
while((text=input.nextLine()) != "*")