第一段代码,实现写入本地
public File writeFile(String strUrl,String writeType, String handler,String orderNo)
throws IOException {
OutputStream os = null;
File file=null;
try {
URL url = new URL(strUrl);
InputStream is = url.openStream();

String value = null;
value = SystemProperties.getSystemPropertie().getQnrPropertyValue("qunar.resultXML.dir");
Tool.outputByConsole("出票接口请求返回XML文件保存路径:"+value);
if(value !=null)
{
value = value.replace("\\", "/");
if(value.lastIndexOf("/") == value.length()-1)
{
fileDir = value.substring(0,value.length()-1);
}
else
{
fileDir = value;
}

}
String filePath = fileDir+"/"+writeType+"/"+Tool.date2Str(new Date(),Constant.DATE_PATTERN_NO_TIME);
String fileName=Tool.date2Str(new Date(),Constant.DATE_PATTERN_NO_SPLIT)+handler+orderNo+"result.xml";
file=new File(filePath+"/"+fileName);
while(!file.exists()){

file.mkdirs();

}
os = new FileOutputStream(filePath + "/" + fileName);

int bytesRead = 0;
byte[] buffer = new byte[8192]; while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
} catch (Exception e2) {
e2.printStackTrace();
} finally {
if (os != null) {
os.close();
}

}
return file;
}
第二段代码,实现写入本地
public void writeIssXML(String filePath,String fileName,String contents) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(filePath+"/"+fileName), true));
writer.write(contents);
writer.close();
}
从代码量来看下面这个要简洁多嗒。。 求指点