java 写文件:行尾加字符 写文件时原内容不变,只是在每行的尾部添加一个字符即可。用RandomAccessFile的writeBytes会发生换行写,不能写到行尾的问题 请问哪位可以帮我提示提示 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我试验了,可以阿,他会覆盖最后的换行符,所以你需要追加import java.io.*;class RandomAccess_Test{ public static void main(String[] args) { try{ RandomAccessFile raf = new RandomAccessFile(new File("D:\\test\\aaa.java"),"rw"); raf.seek(raf.readLine().length()); raf.writeBytes("**"+"\t"); }catch(Exception e){ e.printStackTrace(); } }} 例如xxx1017xxx0022xxx0023xxx0025xxx1669执行后格式就乱了啊 下面的行会爬上上面来~ 可以用StringBuffer的APPEND()和stringTokenizer试试看 楼主试试这个public static void main(String[] args) { try { RandomAccessFile raf = new RandomAccessFile(new File("D:\\1.java"), "rw"); //raf.seek(raf.readLine().length()); while(raf.readLine() != null) { } raf.writeBytes("**" + "\t"); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { try { new testLog().appendChar('a'); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void appendChar(char c) throws IOException { File inFile = new File("D:/temp/1.txt"); File outFile = new File("D:/temp/2.txt"); Reader ir = new FileReader(inFile); Writer ow = new FileWriter(outFile); BufferedReader br = new BufferedReader(ir); BufferedWriter bw = new BufferedWriter(ow); while(br.ready()) { String line = br.readLine(); line += c; bw.write(line); bw.newLine(); } br.close(); bw.close(); }1.txt111122223334444 java封装性和生产消费者的简单疑问 在页面中如何隐藏table? 如何把options的对话框里的名字输出在lable上?? 监听的问题!!谢谢!! rbinfo是什么文件 Workbook读取EXCEL设置时间格式 对 javap 反编译出来的内容 了解的人来看看。 关于java中空字符串问题 成立java开发团队 Application的问题(当天就给分) 问下插入排序 子类访问父类 权限问题
import java.io.*;class RandomAccess_Test
{
public static void main(String[] args)
{
try{
RandomAccessFile raf = new RandomAccessFile(new File("D:\\test\\aaa.java"),"rw");
raf.seek(raf.readLine().length());
raf.writeBytes("**"+"\t");
}catch(Exception e){
e.printStackTrace();
}
}
}
xxx1017
xxx0022
xxx0023
xxx0025
xxx1669执行后格式就乱了啊 下面的行会爬上上面来~
try {
RandomAccessFile raf = new RandomAccessFile(new File("D:\\1.java"),
"rw");
//raf.seek(raf.readLine().length());
while(raf.readLine() != null)
{
}
raf.writeBytes("**" + "\t");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
new testLog().appendChar('a');
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void appendChar(char c) throws IOException {
File inFile = new File("D:/temp/1.txt");
File outFile = new File("D:/temp/2.txt");
Reader ir = new FileReader(inFile);
Writer ow = new FileWriter(outFile);
BufferedReader br = new BufferedReader(ir);
BufferedWriter bw = new BufferedWriter(ow);
while(br.ready()) {
String line = br.readLine();
line += c;
bw.write(line);
bw.newLine();
}
br.close();
bw.close();
}
1.txt1111
2222
333
4444