Java 创建指定格式的文件
2011-01-29 07:40
309 查看
两种思路:
1: 在创建IO流的时候,指定编码
2: 写入内容的时候指定编码格式
1: 在创建IO流的时候,指定编码
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: 写入内容的时候指定编码格式
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文件读写操作指定编码格式
- java删除指定目录下指定格式文件的方法
- Jsoup学习笔记7之File类操作文件:复制只包含指定类型文件的文件夹,并在新创建的同名文件夹中创建同名的另一种格式的文件
- 用VBS创建Excel后,打开时却提示“您尝试打开的文件 的格式与文件扩展名指定的格式不一致”
- Java指定路径文件的自动创建及写入
- Java 创建指定文件路径下的文件夹
- java在指定路径下创建文件,并写入文件内容
- Java指定编码格式读写文件
- Java创建RTF格式的WORD文件代码示例
- Java版本的在指定目录及子目录下创建指定的文件
- 创建一个指定大小格式的文件
- 使用java的输出流写一个json格式的文件在指定目录下
- JAVA读取zip文件 JAVA读取压缩文件 解压zip里面的指定格式文件
- java文件读写操作指定编码格式
- java 文件创建路径指定的问题
- Java 二进制格式文件转换为doc文件并保存在指定路径下
- Java实现获取指定路径下的指定格式的文件;
- iOS --生产JSON格式,创建JSON文件,创建文件夹,指定储存
- java遍历删除指定文件夹下面的相同格式或指定格式的file文件