JAVA的文件创建
2024-08-30 11:14:37
package com.xia;
import java.io.*;
public class test2 { public static void main(String[] args) { //输出流 try {
FileOutputStream fos = new FileOutputStream("d:\\213.txt",true); //true 允许追加写入 String str = "\n大家下午好!天气很不错!"; // \n "转义字符" String str2 = "\n心情不错"; fos.write(str.getBytes()); //覆盖写入 fos.close(); FileInputStream fis = new FileInputStream("d:\\213.txt"); byte[] b = new byte[2048]; int i = fis.read(b); String str1 = new String(b, 0 ,i); System.out.println("读取内容 = "+ str1); fis.close(); } catch (Exception e) { e.printStackTrace();
} } }
FileOutputStream fos = new FileOutputStream("d:\\213.txt",true);
fos.write(str.getBytes());
byte[] b = new byte[2048];
int i = fis.read(b);
String str1 = new String(b, 0 ,i);
System.out.println("读取内容 = "+ str1);
fis.close();
package com.xia; import java.io.*; public class test3 { public static void main(String[] args) { try { FileReader fr = new FileReader("d:\\213.txt"); char[] c= new char[2048]; int i = fr.read(c); String str = new String (c,0,i); System.out.println("读取内容 = " + str); fr.close(); //写入 FileWriter fw = new FileWriter("d:\\213.txt", true); fw.write("\n新追加的内容"); fw.close(); } catch (Exception e) { e.printStackTrace();
}
}
}
最新文章
- AFNetworking 3.0 源码解读(二)之 AFSecurityPolicy
- Laravel框架 mysql 数据库 —— 基本使用
- eclipse中添加python开发环境
- UI键盘通知
- bzoj3714: [PA2014]Kuglarz
- 各种ORM安装
- NFC(12)使用Android Beam技术传输文本数据及它是什么
- Android ListView 滚动的N种方法
- The run destination XXX的 iPhone is not valid for Running the scheme 'Day7通讯录Demo'.
- AIR学习教程(一)
- [2012-04-25]shell大括号参数扩展(Parameter Expansion)
- Codeforces Round #352 (Div. 2) (A-D)
- 文本在div中始终垂直居中
- oracle中rownum的使用
- Python_set集合部分功能介绍
- sliver
- Pandas 基础(12) - Stack 和 Unstack
- php 配置文件不加载的一次配置
- SDOI2017相关分析 线段树
- scala 爬虫 去除不能存储的特殊字符