我正在尝试运行此代码,该代码本来应该是我老师的简单剪切和粘贴作业。但是,按照说明进行操作后,我仍然收到此错误消息:
“找不到指定的文件ShapeData.txt。”
回到第30行。
我确实将文件与其他所有文件都剪切并粘贴到了相同的文件夹中,所以我不确定为什么仍然出现此错误。我还阅读了有关在命令行中执行某项操作的信息,但不确定该执行什么操作。
(哦,这不是家庭作业,也不是我可以上年级的任何东西。这只是我们可以用来更好理解的内容。)
这是我的代码,或者至少是第一行。
/**
* Concepts demonstrated:
* Object Inheritance
* Interfaces
* Interface Implementation
* Reading Data from a File
* Sorting an Array
* Manipulating Strings
*/
import java.util.Scanner;
/**
* This lab demonstrates the basics of object-oriented programming.
*/
public class Lab8 {
private static Shape[] shapes; // An array to hold all the shape objects
public static void main(String[] args) {
DataReader reader = new DataReader("ShapeData.txt");// The reader is used to read data from a file
// Display program information
System.out.println("Ima Java Programmer");
System.out.println("Shape Info");
// Load data from the file
if(reader.loadData("ShapeData.txt")) { // The filename is entered using a command-line argument
shapes = reader.getShapeData(); // Store the arrays in the array
// Display how many shapes were read from the file
System.out.println("Successfully loaded " + shapes[0].getCount() +
" shapes from the selected data file!");
displayMenu();
}
}
最佳答案
ShapeData.txt file must be in your working directory
,因为这里没有指定完整路径。工作目录可能是您的Java bin目录