81,094
社区成员
发帖
与我相关
我的任务
分享
package com.sz.zgzstudy;
import java.io.IOException;
import java.io.InputStream;
public class test6 {
public static void main(String[] args) {
String pathName = "com/sz/zgzstudy/1.txt";
byte[] buff = new byte[1024];
int len = 0;
//从classpath路径里获取文件。
InputStream is = ClassLoader.getSystemResourceAsStream(pathName);
// 从文件读取数据
try {
while((len = is.read(buff)) != -1) {
System.out.write(buff, 0, len); //打印到控制台
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}