FileOutputStream fo = null;
DataOutputStream ds = null;
OutputStreamWriter osw = null;
try{
fo = new FileOutputStream(Common.strSLExtXMLWritePath+"lists"+xmlURL); //set output file path and name.
ds = new DataOutputStream(fo);
//osw = new OutputStreamWriter(fo);
ds.writeUTF(StrXMl.toString());
//osw.write(StrXMl.toString());
System.out.println(Common.strSLExtXMLWritePath+"lists"+xmlURL);
//System.out.println("@@@System.out.osw"+osw.getEncoding());
//osw.flush();
//osw.close();
ds.flush();
ds.close();
fo.close();
}catch(Exception ex){
ex.printStackTrace();
}
这是我写的代码.怎么会前面头有乱码?请指教.
DataOutputStream ds = null;
OutputStreamWriter osw = null;
try{
fo = new FileOutputStream(Common.strSLExtXMLWritePath+"lists"+xmlURL); //set output file path and name.
ds = new DataOutputStream(fo);
//osw = new OutputStreamWriter(fo);
ds.writeUTF(StrXMl.toString());
//osw.write(StrXMl.toString());
System.out.println(Common.strSLExtXMLWritePath+"lists"+xmlURL);
//System.out.println("@@@System.out.osw"+osw.getEncoding());
//osw.flush();
//osw.close();
ds.flush();
ds.close();
fo.close();
}catch(Exception ex){
ex.printStackTrace();
}
这是我写的代码.怎么会前面头有乱码?请指教.
解决方案 »
- jquery的ajax请求struts2的方法返回json数据,ajax请求问题。
- 一个基于web的管理系统项目分析出的一些难点和疑惑,求解。。。
- struts2 接收不到参数,那个高手帮忙看看呀
- 一个HQL语句问题!!
- tomcat 服务器没有响应问题
- 600分,关于Sun Message Queue的集群!
- UNIX上的TOMCAT
- 有谁知道怎么用netbeans编译ejb的java文件么??
- 请问谁运行过《Java XML 编程指南》中的代码?
- 如何把myeclipse里自带的JDK替换成自己的电脑安装的JDK
- 请问:我在xfire中使用的spring配置为什么总是无效?
- 关于xfire的webservice的客户端
fo.write(nbs);
DataOutputStream ds = null;
FileWriter fw= null;
OutputStreamWriter osw = null;
try{
fo = new FileOutputStream(Common.strSLExtXMLWritePath+"lists"+xmlURL); //set output file path and name.
osw = new OutputStreamWriter(fo,"UTF-8");
BufferedWriter bfw=new BufferedWriter(osw);
bfw.write(new String(StrXMl.toString().getBytes("UTF-8"),"UTF-8"));
System.out.println(Common.strSLExtXMLWritePath+"lists"+xmlURL);
bfw.flush();
bfw.close();
fo.close();
}catch(Exception ex){
ex.printStackTrace();
}
可以已经
好像只用写的时候指定编码就可以了