我正在尝试运行这段代码,该代码应该是我老师的简单作业。但是,按照说明操作后,我仍然收到此错误消息:
“找不到指定的文件,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();
}
}