java生成unicode编码格式的txt文件
2016-06-23 16:12
483 查看
//strFilePath:文件名,strText:要是写入的内容
public static boolean writefile(String strFilePath,String strText)
{
FileOutputStream fos = null;
BufferedOutputStream osw = null;
File file =new File(strFilePath);
try
{
fos = new FileOutputStream(file);
osw = new BufferedOutputStream(fos);
byte[] bom={-1, -2};
osw.write(bom);
osw.write(strText.getBytes("UTF-16LE"));
osw.flush();
fos.close();
osw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return true;
}
public static boolean writefile(String strFilePath,String strText)
{
FileOutputStream fos = null;
BufferedOutputStream osw = null;
File file =new File(strFilePath);
try
{
fos = new FileOutputStream(file);
osw = new BufferedOutputStream(fos);
byte[] bom={-1, -2};
osw.write(bom);
osw.write(strText.getBytes("UTF-16LE"));
osw.flush();
fos.close();
osw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return true;
}
相关文章推荐
- Java总结篇系列:Java泛型
- java中ThreadLocal类的使用
- Spring入门第2天--面向切面编程入门
- java多线程--“朴素版”生产者消费者问题
- Mybatis中javaType和jdbcType对应关系
- Mybatis中javaType和jdbcType对应关系
- springmvc 4 返回json数据
- JAVA 数组类型
- springMVC实现文件上传
- springmvc 传出参数
- spring学习总结-第二讲
- Hibernate注解使用以及Spring整合
- java多线程--优先级
- Error:The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location:
- Mybatis学习之个人笔记(一)
- java线程池和关闭线程池中的线程
- Spring 事务管理高级应用难点剖析: 第 3 部分
- 2016.6.23笔记(1)-struts初探
- java文件下载断点续传
- 解决NetBeans运行web项目时出现的“未能正确设置java DB”问题