【发布时间】:2018-06-04 20:05:22
【问题描述】:
您好,我正在尝试使用凯撒密码在 java 中编码一个 txt 文件。我自己决定转移,我已经编写了下面的代码,但我得到了:
java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
有人可以帮我解决吗?谢谢!
public class zevenedesim {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("words.txt"));
PrintStream output = new PrintStream(new File("words.txt"));
String teksti = input.nextLine();
zevenedesim(teksti, output);
}
public static void zevenedesim(String text, PrintStream output) {
int i = 0;
String s;
Scanner data = new Scanner(text);
if (data.hasNext()) {
s = data.next();
if (s.charAt(i) >= 97 && s.charAt(i) <= 120) {
int x = s.charAt(i) - 97;
x = (x + 2) % 26;
if (x < 0)
x += 26;
// = (char) (x + 32);
}
output.print(" " + data.next());
}
}
}
【问题讨论】:
-
你的文件是空的。
-
你正在读写同一个文件。
-
我修复了它,但是如果我写“Hello Java”,输出将是“Java”
标签: java