File file=new File(path);
FileInputStream in = null;
try {
in = new FileInputStream(file);
//创建字节数组,用于接收从文件中读取的字节
int size=in.available();
byte buf[] = new byte[size];
String string = ""; //接收字节转化的字符串
int length = in.read(buf);
string = new String(buf,"GB2312");//将字节转化成字符串
// JSONObject json = JSONObject.fromObject(string);
OrderDetailsRes orderDetailsRes=JSON.parseObject(string,OrderDetailsRes.class);
orderService.resolveOrderData(orderDetailsRes);
} catch (IOException ex) {
ex.printStackTrace();
}finally {
if (in!=null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
文件内容为String,则输出也为String。