File 读取本地文件转化成字符串

来源:互联网 发布:手机excel表格软件 编辑:程序博客网 时间:2024/06/08 09:09
第一种File file =new File(path);if(!file.exists()||!file.isFile())return "file is not exists";FileInputStream inputStream =null;try {inputStream=new FileInputStream(file);    ByteBuffer buffer=ByteBuffer.allocate((int)file.length());    inputStream.getChannel().read(buffer);        String strPnr=new String(buffer.array());第二种:URL url=ReceiveXmlCommand.class.getClassLoader().getResource(path);        String strPnr = IOUtils.toString(url.openStream());    IOUtils.closeQuietly(inputStream);
 
 
path 路径看需求是怎么获得了 


 

0 0