[英]No such file error when using a Java Makefile in Linux
我需要使用makefile编译.java文件。 我做了一个相当简单的但是当我运行生成的.class文件时,我收到以下错误
Exception in thread "main" java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:947)
at BadThread.<init>(Base.java:20)
at Base.main(Base.java:13)
我知道Makefile不是运行java代码的最佳方法,但这是一个要求。
这是我的makefile:
JFLAGS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
Base.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
$(RM) *.class
我正在尝试编译的文件是这样的:
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Base {
public static void main(String[] args) throws IOException {
for(int i=0;i<10;i++){
new Thread(new BadThread("./output/"+i+".text")).start();
}
}
}
class BadThread implements Runnable{
public BadThread(String filePath) throws IOException{
File f=new File(filePath);
if(f.exists()==false){f.createNewFile();}
dos=new DataOutputStream(new FileOutputStream(filePath));
}
private DataOutputStream dos;
double val=0.0D;
@Override
public void run() {
try{
for(int i=0;i<1024000;i++){
val=Math.random();
for(int j=0;j<8;j++){
dos.writeDouble(val+j);
}
}
dos.flush();
dos.close();
}catch(Exception e){return;}
}
}
您尝试创建新文件的目录output
不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.