java.io.FileNotFoundException,为什么?
我已经下载了SSJ库,一个用于随机模拟的Java库。其中一个文件需要打开*.dat文件 我试图以下载的方式运行该文件,dat文件也在那里,但每次都会收到FileNotFoundException 以下是源代码:java.io.FileNotFoundException,为什么?,java,file,Java,File,我已经下载了SSJ库,一个用于随机模拟的Java库。其中一个文件需要打开*.dat文件 我试图以下载的方式运行该文件,dat文件也在那里,但每次都会收到FileNotFoundException 以下是源代码: import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.StringTokenizer; import umontreal.iro.lec
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import umontreal.iro.lecuyer.randvar.ExponentialGen;
import umontreal.iro.lecuyer.rng.MRG32k3a;
import umontreal.iro.lecuyer.rng.RandomStream;
import umontreal.iro.lecuyer.simevents.Event;
import umontreal.iro.lecuyer.simevents.Sim;
import umontreal.iro.lecuyer.simprocs.Resource;
import umontreal.iro.lecuyer.simprocs.SimProcess;
import umontreal.iro.lecuyer.stat.Tally;
public final class Jobshop {
int nbMachTypes; // Number of machine types M.
int nbTaskTypes; // Number of task types N.
double warmupTime; // Warmup time T_0.
double horizonTime; // Horizon length T.
boolean warmupDone; // Becomes true when warmup time is over.
Resource[] machType; // The machines groups as resources.
Jobshop.TaskType[] taskType; // The task types.
RandomStream streamArr = new MRG32k3a(); // Stream for arrivals.
BufferedReader input;
public Jobshop() throws IOException { readData(); }
// Reads data file, and creates machine types and task types.
void readData() throws IOException {
// input = new BufferedReader (new FileReader ("Jobshop.dat"));
input = new BufferedReader (new FileReader ("JobShop.dat"));
StringTokenizer line = new StringTokenizer (input.readLine());
warmupTime = Double.parseDouble (line.nextToken());
line = new StringTokenizer (input.readLine());
horizonTime = Double.parseDouble (line.nextToken());
line = new StringTokenizer (input.readLine());
nbMachTypes = Integer.parseInt (line.nextToken());
nbTaskTypes = Integer.parseInt (line.nextToken());
machType = new Resource[nbMachTypes];
for (int m=0; m < nbMachTypes; m++) {
line = new StringTokenizer (input.readLine());
String name = line.nextToken();
int nb = Integer.parseInt (line.nextToken());
machType[m] = new Resource (nb, name);
}
taskType = new Jobshop.TaskType[nbTaskTypes];
for (int n=0; n < nbTaskTypes; n++)
taskType[n] = new Jobshop.TaskType();
input.close();
}
class TaskType {
public String name; // Task name.
public double arrivalRate; // Arrival rate.
public int nbOper; // Number of operations.
public Resource[] machOper; // Machines where operations occur.
public double[] lengthOper; // Durations of operations.
public Tally statSojourn; // Stats on sojourn times.
// Reads data for new task type and creates data structures.
TaskType() throws IOException {
StringTokenizer line = new StringTokenizer (input.readLine());
statSojourn = new Tally (name = line.nextToken());
arrivalRate = Double.parseDouble (line.nextToken());
nbOper = Integer.parseInt (line.nextToken());
machOper = new Resource[nbOper];
lengthOper = new double[nbOper];
for (int i = 0; i < nbOper; i++) {
int p = Integer.parseInt (line.nextToken());
machOper[i] = machType[p-1];
lengthOper[i] = Double.parseDouble (line.nextToken());
}
}
// Performs the operations of this task (to be called by a process).
public void performTask (SimProcess p) {
double arrivalTime = Sim.time();
for (int i=0; i < nbOper; i++) {
machOper[i].request (1); p.delay (lengthOper[i]);
machOper[i].release (1);
}
if (warmupDone) statSojourn.add (Sim.time() - arrivalTime);
}
}
public class Task extends SimProcess {
Jobshop.TaskType type;
Task (Jobshop.TaskType type) { this.type = type; }
public void actions() {
// First schedules next task of this type, then executes task.
new Jobshop.Task (type).schedule (ExponentialGen.nextDouble
(streamArr, type.arrivalRate));
type.performTask (this);
}
}
Event endWarmup = new Event() {
public void actions() {
for (int m=0; m < nbMachTypes; m++)
machType[m].setStatCollecting (true);
warmupDone = true;
}
};
Event endOfSim = new Event() {
@Override
public void actions() { Sim.stop(); }
};
public void simulateOneRun() {
SimProcess.init();
endOfSim.schedule (horizonTime);
endWarmup.schedule (warmupTime);
warmupDone = false;
for (int n = 0; n < nbTaskTypes; n++) {
new Jobshop.Task (taskType[n]).schedule (ExponentialGen.nextDouble
(streamArr, taskType[n].arrivalRate));
}
Sim.start();
}
public void printReportOneRun() {
for (int m=0; m < nbMachTypes; m++)
System.out.println (machType[m].report());
for (int n=0; n < nbTaskTypes; n++)
System.out.println (taskType[n].statSojourn.report());
}
static public void main (String[] args) throws IOException {
Jobshop shop = new Jobshop();
shop.simulateOneRun();
shop.printReportOneRun();
}
}
导入java.io.BufferedReader;
导入java.io.FileReader;
导入java.io.IOException;
导入java.util.StringTokenizer;
导入umontreal.iro.lecuyer.randvar.ExponentialGen;
导入umontreal.iro.lecuyer.rng.MRG32k3a;
导入umontreal.iro.lecuyer.rng.RandomStream;
导入umontreal.iro.lecuyer.simevents.Event;
导入umontreal.iro.lecuyer.simevents.Sim;
导入umontreal.iro.lecuyer.simprocs.Resource;
导入umontreal.iro.lecuyer.simprocs.SimProcess;
导入umontreal.iro.lecuyer.stat.Tally;
公共末班工作间{
int nbMachTypes;//机器类型的数量M。
int nbTaskTypes;//任务类型的数量N。
双预热时间;//预热时间T\u 0。
双水平时间;//水平长度T。
布尔预热门;//预热时间结束时变为真。
Resource[]machType;//机器分组为资源。
Jobshop.TaskType[]TaskType;//任务类型。
RandomStreamArr=new MRG32k3a();//到达流。
缓冲读取器输入;
public Jobshop()引发IOException{readData();}
//读取数据文件,并创建计算机类型和任务类型。
void readData()引发IOException{
//输入=新的BufferedReader(新的文件阅读器(“Jobshop.dat”);
输入=新的BufferedReader(新的文件阅读器(“JobShop.dat”);
StringTokenizer行=新的StringTokenizer(input.readLine());
warmupTime=Double.parseDouble(line.nextToken());
line=新的StringTokenizer(input.readLine());
horizontame=Double.parseDouble(line.nextToken());
line=新的StringTokenizer(input.readLine());
nbMachTypes=Integer.parseInt(line.nextToken());
nbTaskTypes=Integer.parseInt(line.nextToken());
machType=新资源[nbMachTypes];
对于(int m=0;m
以下是输出:
Exception in thread "main" java.io.FileNotFoundException: JobShop.dat (O sistema não conseguiu localizar o ficheiro especificado)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at java.io.FileReader.<init>(FileReader.java:58)
at Jobshop.readData(Jobshop.java:31)
at Jobshop.<init>(Jobshop.java:26)
at Jobshop.main(Jobshop.java:133)
Java Result: 1
线程“main”java.io.FileNotFoundException中的异常:JobShop.dat(O sistema nãO conseguiu localizar O ficheiro specificado)
在java.io.FileInputStream.open(本机方法)
位于java.io.FileInputStream。(FileInputStream.java:138)
位于java.io.FileInputStream。(FileInputStream.java:97)
位于java.io.FileReader。(FileReader.java:58)
在Jobshop.readData(Jobshop.java:31)
在Jobshop(Jobshop.java:26)
在Jobshop.main(Jobshop.java:133)
Java结果:1
有没有关于如何修复它的线索
提前感谢。按照文件的引用方式,它希望在您运行应用程序的位置找到文件。似乎在那里找不到它。请确保指定与当前工作目录(运行java命令的目录)相关的.dat文件路径。您的路径可能错误:
input = new BufferedReader (new FileReader ("JobShop.dat"));
因为我正在使用NetBeans IDE运行项目
input = new BufferedReader (new FileReader ("src/JobShop.dat"));