第一段代码,实现写入本地
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();
}
从代码量来看下面这个要简洁多嗒。。 求指点
解决方案 »
- 给个关于JAVAEE可以下载视频的网站吧!
- js 小题,请高手指点
- jsp接收数据写入oracle数据库
- axis2 客户端 如何加入用户名密码验证 ?
- 问个问题
- 用commons-net ftp上传excel或者word文件到windows下的FTP服务器,文件会打不开
- Tomcat服务器不解释jsp代码是怎么回事啊?
- STRUTS1.1中用<html:errors/>,中文不能正确显示?
- 在webservice 启动后 客户端用 soapui发送报文 报如下错误 怎么解决 谢谢
- 大家一起来谈谈Java语言中关于:”一切都是对象“这句话的理解
- js怎么实现文本框中的颜色变化
- 三大框架整合出现错误
没啥可比性的,因为代码2调用之前的代码没有,也就是代码2的filePath,fileName, contents是怎么来的?