使用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]);
}
}

 

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM