【发布时间】:2017-12-06 00:08:28
【问题描述】:
我正在阅读一个文本文件(我在其中写了一些句子的文件)并打印它的内容,一切都很顺利,直到我从 PDF 文件中复制了相同的句子,然后没有任何东西打印到控制台中,让我构建成功。
这是我的代码:
File f=new File("input.txt");
Scanner sc=new Scanner(f);
while (sc.hasNext())
{
String line=sc.nextLine();
int i=0;
while ( i< line.length())
{
char c=line.charAt(i);
System.out.println(c);
i++;
}
}
sc.close();
文本文件的内容(无论是我自己写的句子还是从PDF复制):
{sample program in TINY language- computes factorial}
read x;{input an integer}
if 0<x then {don’t compute if x<=0}
fact:=1;
repeat
fact:=fact*x;
x:=x-1
我做错了什么,如果我想将 PDF 文件中的句子复制到我正在阅读的文本文件中该怎么办
【问题讨论】:
-
将
sc.hasNext()更改为sc.hasNextLine()。
标签: java file java.util.scanner