做了,,一下午了,,,可能是对io流使用的很不熟练,,尝试过好几种思路还没实现,,
希望大神,,有时间给个思路清晰的,答案,,,谢谢谢鞋了。
希望大神,,有时间给个思路清晰的,答案,,,谢谢谢鞋了。
解决方案 »
- 3.9898/4=0.99745,为什么(3.9898/4)*100=99.74499999999999,类型为double,有程序
- 谁能帮我完美这个程序?
- 用过ibatis的高手请进(只有10分了)
- java中调用sqlserver的存储过程(游标分页的存储过程)
- 那里有jbuilder6 或者7、8、9 都可以,那里有比较快的下载啊!!给分!急啊!!!!
- 如何定义和绘制线串?
- 关于URL的问题?
- 关于AWT动画的问题
- instance 和 object 的区别?
- 关于robocode的源程序的一点建议
- 有关Iterator的一个问题没懂。
- 请大神帮忙一下解决: Note: further occurrences of HTTP header parsing errors will be logge
如下:file是文件路径 content是内容
public static void write(String file, String conent) throws IOException {
File file2 = new File(file);
if (!file2.exists()) {
file2.createNewFile();
}
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
out.write(conent + "\r\n");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
* 数据源文件信息:
* 张三;男;1529366;
* 小米;女;13;
* lili;女;11111;
* <p>
* 数据源要求:以';'分割属性
*/
public class IO { //数据源条数
static final int COUNT = 3;
//保存从文件中读取到的信息;
static String[][] phoneArrs = new String[COUNT][]; //创建数据源文件对象(从该文件对象读取信息)
static File readFiel = new File("src/phoneData.txt");
//创建输出文件对象(保存输出的信息)
static File writeFile = new File("src/phoneBook.txt"); //输出字节流
static OutputStream out;
//输入缓冲流
static BufferedReader br; /**
* @Author: hyh
* 读取文件信息
*/
static void readBook() {
try {
//实例化输入流对象
br = new BufferedReader(new FileReader(readFiel));
//用于保存读取到的字符串(readLine每次读取一行)
String str;
//循环读取文件,直到文件末尾
for (int i = 0; i < COUNT && (str = br.readLine()) != null; i++) {
String[] strings;
//按';'分割字符串,得到一个新的字符串数组
strings = str.split(";");
//把得到的字符串数组存放到phoneBook中
phoneArrs[i] = strings;
}
//关闭流
br.close();
System.out.println("读取完成");
} catch (IOException e) {
e.printStackTrace();
}
} /**
* @Author: hyh
* 把数组信息写到文件中
*/
static void writeBook() {
String[] temp; //表示一条联系人信息
try {
//实例化输出流对象(追加信息)
out = new FileOutputStream(writeFile, true); for (int i = 0; i < phoneArrs.length; i++) {
temp = phoneArrs[i];
//写入一条信息
for (int j = 0; j < temp.length; j++) {
out.write(temp[j].getBytes());
//添加符号
out.write(';');
}
//每条信息写入完成后换行
out.write('\n');
}
//关闭流
out.flush();
out.close();
System.out.println("写入完成");
} catch (IOException e) {
e.printStackTrace();
}
} public static void main(String[] args) {
readBook();
//读取完成后,对数据进行修改
phoneArrs[1][1] = "修改的数据111";
//修改完成,写入文件
writeBook();
}}