Java 创建指定格式的文件
2013-09-04 14:08
239 查看
两种思路:
1: 在创建IO流的时候,指定编码
[java] view
plaincopy
try{
File file=new File("C:/11.jsp");
OutputStream out=new FileOutputStream(file);
BufferedWriter rd = new BufferedWriter(new OutputStreamWriter(out,"utf-8"));
rd.write("hello");
rd.close();
out.close();
}catch(IOException e){
e.printStackTrace();
}
2: 写入内容的时候指定编码格式
[java] view
plaincopy
public static void main(String[] agrs) throws IOException {
FileOutputStream out = null;
try {
out = new FileOutputStream(new File("a.txt"));
// 将数据,转换成某一个字符集的byte数组,然后直接写入文件即可
out.write("你好hello".getBytes("UTF-8"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
out.close();
}
}
1: 在创建IO流的时候,指定编码
[java] view
plaincopy
try{
File file=new File("C:/11.jsp");
OutputStream out=new FileOutputStream(file);
BufferedWriter rd = new BufferedWriter(new OutputStreamWriter(out,"utf-8"));
rd.write("hello");
rd.close();
out.close();
}catch(IOException e){
e.printStackTrace();
}
2: 写入内容的时候指定编码格式
[java] view
plaincopy
public static void main(String[] agrs) throws IOException {
FileOutputStream out = null;
try {
out = new FileOutputStream(new File("a.txt"));
// 将数据,转换成某一个字符集的byte数组,然后直接写入文件即可
out.write("你好hello".getBytes("UTF-8"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
out.close();
}
}
相关文章推荐
- Java 创建指定格式的文件
- java遍历删除指定文件夹下面的相同格式或指定格式的file文件
- Java 二进制格式文件转换为doc文件并保存在指定路径下
- Java实现获取指定路径下的指定格式的文件;
- iOS --生产JSON格式,创建JSON文件,创建文件夹,指定储存
- 以Java属性文件的格式创建Hibernate的配置文件和DTD特殊符号作用
- java创建目录+文本文件+输出文本到指定文件
- 小时代5-Perl创建指定文件编码格式(如utf-8)
- (25)JAVA.IO--使用Java创建指定大小的空文件
- Java(Android)写文件时指定编码格式的问题
- Java实用篇--如何在指定文件位置创建文件
- java文件读写操作指定编码格式[转]
- java遍历删除windows下的指定文件夹下面的相同格式或指定格式的file文件
- java文件读写操作指定编码格式
- java字节流和字符流操作文件,指定编码写入和读取,递归创建上层目录
- Java 实现获取指定文件夹下的指定格式的所有文件
- Java递归查找指定目录下的特定格式的文件 并压缩到指定目录下
- Java 遍历文件夹 取出指定文件格式的文件
- 使用Java创建指定大小的空文件
- Java-基础 文件操作IO 在指定目录中创建文件