这是我读取文本文件的代码.当我运行此代码时,输出会一直显示"找不到文件.",这是消息FileNotFoundException.我不确定这段代码中的问题是什么.
显然这是java的一部分.对于整个java文件,它要求用户输入内容并使用输入作为名称创建文本文件.之后,用户应该再次输入之前创建的文本文件的名称(假设用户输入正确),然后程序应该读取文本文件.我已正确完成程序的其他部分,但问题是当我再次输入名称时,它只是找不到文本文件,尽管它们位于同一文件夹中.
public static ArrayList<DogShop> readFile()
{
try
{ // The name of the file which we will read from
String filename = "a.txt";
// Prepare to read from the file, using a Scanner object
File file = new File(filename);
Scanner in = new Scanner(file);
ArrayList<DogShop> shops = new ArrayList<DogShop>();
// Read each line until end of file is reached
while (in.hasNextLine())
{
// Read an entire line, which contains all the details for 1 account
String line …Run Code Online (Sandbox Code Playgroud)