gpt4 book ai didi

java - 在eclipse中读取java中的.txt文件

转载 作者:行者123 更新时间:2023-12-02 05:26:17 24 4
gpt4 key购买 nike

我正在尝试从我的计算机读取文件,但它说java.io.FileNotFoundException(系统找不到指定的文件)

System.out.println("READING FILE"); 


File file = new File("Testing.txt"); //Reading file from E
FileInputStream in = null;
BufferedInputStream buff = null;
DataInputStream data= null;

String Line=""; // declare a string
try
{

in = new FileInputStream(file); // pick up the file

buff = new BufferedInputStream(in);
data = new DataInputStream(buff);

while (data.available() != 0)
{ // Read the file line by line till it reaches the end of file

Line=Line+data; // concatenate line into string

System.out.println(data.readLine()); // print line by line
}

} catch (IOException e)

{
e.printStackTrace();
}

最佳答案

File file = new File("E:\\Testing.txt"); 

如果您尝试访问 E,这是实现此目的的方法之一

关于java - 在eclipse中读取java中的.txt文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25980887/

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