第一种
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 路径看需求是怎么获得了