IO读文件

xiaoxiao2021-02-28  100

package servlet;import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; public class ReadTest { public ReadTest() { // TODO Auto-generated constructor stub } public static void main(String[] args) { File file=new File("D:\\abc.txt"); StringBuffer jsonStr=new StringBuffer(); try { InputStream in=new FileInputStream(file); byte[] b=new byte[2048]; while((in.read(b))!=-1){ String b1=new String(b,"utf-8"); jsonStr.append(b1); } } catch (Exception e) { // TODO Auto-generated catch } System.out.println(jsonStr.toString().trim()); } }

 

转载请注明原文地址: https://www.6miu.com/read-32623.html

最新回复(0)