请教一个示例,如何读取一个文本文件的每一行,将一行内容进行处理,处理后将结果写在这个文件的末尾,注意是在同一行啊,不是文件的末尾 本人初学,现在只会将文件读取出来,请问如果要实现上面的效果,应该怎么处理呢?请最好给出示例代码多谢!!!!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try { RandomAccessFile file = new RandomAccessFile("F:\\a.txt", "rw"); ArrayList array = new ArrayList(); while(file.getFilePointer() < file.length()){ String a = file.readLine(); a += "gongchajkhsfhsdjfhjskfhjskhfjksfjs\r\n"; array.add(a); } file.seek(0); Iterator it = array.iterator(); while(it.hasNext()){ file.writeBytes((String)it.next()); } } catch (Exception ex) { }我实在是没办法了 File outFile = new File("file.txt");RandomAccessFile waf = new RandomAccessFile(outFile, "rw");String str;while ((str = in.readLine()) != null) { // str就是读取到的一行 //进行你的处理,比如str=str+"end"; waf.seek(waf.length()); // 指向新文件的末尾 waf.writeBytes(result); // 写入到新文件}waf.close();新文件就是修改后的内容了 File outFile = new File("file.txt");RandomAccessFile waf = new RandomAccessFile(outFile, "rw");String str;while ((str = in.readLine()) != null) { // str就是读取到的一行 //进行你的处理,比如str=str+"end"; waf.seek(waf.length()); // 指向新文件的末尾 waf.writeBytes(str); // 写入到新文件}waf.close();新文件就是修改后的内容了 java 从txt文件中读取数字 每行有且只有两个数字 存入arraylist里 包路径错误请教 Java 在linux下连接SQLite的问题 RandomAccessFile中的seek()问题!!!! 诚心请教JAVA图形用户界面和IO处理问题! 已知一个InputStream流,请问怎样转换成一个文件? 大送分呀大送分,很简单的问题,告诉我它们运算的流程~ 求救:让我烦的简单问题 - jdbc,resultset 已经在做java的工作了,还有必要去考scjp吗? JAVA 要学些什么?? 高? 【求助】在线程中怎么访问父进程的内存????? 数据库连不上
RandomAccessFile file = new RandomAccessFile("F:\\a.txt", "rw");
ArrayList array = new ArrayList();
while(file.getFilePointer() < file.length()){
String a = file.readLine();
a += "gongchajkhsfhsdjfhjskfhjskhfjksfjs\r\n";
array.add(a);
}
file.seek(0);
Iterator it = array.iterator();
while(it.hasNext()){
file.writeBytes((String)it.next());
}
}
catch (Exception ex) {
}
我实在是没办法了
RandomAccessFile waf = new RandomAccessFile(outFile, "rw");String str;
while ((str = in.readLine()) != null) {
// str就是读取到的一行
//进行你的处理,比如str=str+"end";
waf.seek(waf.length()); // 指向新文件的末尾
waf.writeBytes(result); // 写入到新文件
}waf.close();新文件就是修改后的内容了
RandomAccessFile waf = new RandomAccessFile(outFile, "rw");String str;
while ((str = in.readLine()) != null) {
// str就是读取到的一行
//进行你的处理,比如str=str+"end";
waf.seek(waf.length()); // 指向新文件的末尾
waf.writeBytes(str); // 写入到新文件
}waf.close();新文件就是修改后的内容了