gpt4 book ai didi

java - 线程 "main"java.lang.NumberFormatException : For input string "F:/TextFiles/loginaccs.txt" 中的异常

转载 作者:行者123 更新时间:2023-11-29 06:55:06 30 4
gpt4 key购买 nike

final String FileName = "F:/TextFiles/loginaccs.txt";
InputStream FileNameIS = new ByteArrayInputStream(FileName.getBytes());
try {
BufferedReader file = new BufferedReader(new InputStreamReader(FileNameIS));
int NoOfUsers = Integer.parseInt(file.readLine());
String[][] Accounts = new String[NoOfUsers][2];
for (int i=1; i>NoOfUsers; i++) {
Accounts[i][1] = file.readLine();
Accounts[i][2] = file.readLine();
}
for (int i=1; i>NoOfUsers; i++) {
System.out.println(Accounts[i][1]);
System.out.println(Accounts[i][2]);
}
file.close();

} catch (IOException e) {
System.out.println("ERROR: unable to read file.");
e.printStackTrace();
}

这是我的代码,试图从文本文件中读取一些数据,如下所示:(F:/TextFiles/loginaccs.txt")

4
Tom
123456
Mary
12345
Peter
1234
D3K
123

然后控制台说有某种异常。

Exception in thread "main" java.lang.NumberFormatException: For input string: "F:/TextFiles/loginaccs.txt"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.RPGOfTheCorrupted.Program.Main.Login(Main.java:27)
at com.RPGOfTheCorrupted.Program.Main.main(Main.java:19)

我不知道为什么会这样,如果程序有任何问题,有人可以回答我吗?非常感谢。

最佳答案

您不是从 File 读取,您是从 String(代表文件名)读取:

BufferedReader file = new BufferedReader(new InputStreamReader(FileNameIS));

试试这个:

BufferedReader file = new BufferedReader(new InputStreamReader(new FileInputStream(FileName)));

关于java - 线程 "main"java.lang.NumberFormatException : For input string "F:/TextFiles/loginaccs.txt" 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36065071/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com