[英]How to read bin file located in java project's folder in eclipse
我想在java中读取bin文件。 我在项目文件夹中创建名称为doc的文件夹,并在doc文件夹中添加了bin文件。 我想阅读这段代码;
String fileName = "10.bin";
byte[] data = new byte[1024];
int readBytes;
try {
FileInputStream in = new FileInputStream(fileName);
while((readBytes = in.read(data)) != -1){
System.out.println("read " + readBytes + "bytes, and placed them into temp array named data");
}
in.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
名为10.bin的bin文件位于doc文件夹中,如图所示
我无法使用此代码访问文件。 请帮帮我。
首先,您必须提供fileName的路径
File fileName = new File("your fileName path goes here");
FileInputStream in = new FileInputStream(fileName);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.