使用inputStream读取文件

public class DemoT {

public static void main(String[] args) throws Exception {
ClassPathResource resource = new ClassPathResource("20200916_order_detail.csv");
String path = resource.getPath();
InputStream in = resource.getInputStream();
byte[] b = new byte[2048];

int c = 0;

String str = "";

while((c = in.read(b)) != -1){
str += new String(b,0,c);//在此拼接
}

String[] s = str.split("\n");//以\n来截取!转化为数组!
System.out.println(s.length);
System.out.println(s[1]);
System.out.println(s[2]);
}
}

 

如果是文件是其他路径下的

 

posted @ 2020-09-21 16:35  幽魂~~  阅读(971)  评论(0编辑  收藏  举报