如何在原有的文件上追加新内容 如何在原有的文件上追加 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 FileWriter fos = new FileWriter("FileOutputStream.dat",true); C++里我会这样写:#include <fstream>ofstream writeFile("aaa.txt");ifstream readFile("aaa.txt",ios::binary);int count=0;char * buf= new char[100]; //这是将来写入文件末尾的内容if(readFile.good()){ while(!readFile.eof()) { count++; readFile.get(); } writeFile.seekp(count-1); //这一句是将文件的指针移动到文件最后 for(int i=0; i<100; i++) { writeFile<<buf[i]; writeFile.seekp(++count); }}else cout<<"The File may be crushed or not exist";以上程序最近写过,记得比较清楚;以前用java也写过完全一样的,不过不记得了,原理基本一样吧,都是移动文件指针,然后在输出。 import java.io.*;public class MyTest{ public static void main(String []args) { try { RandomAccessFile raf=new RandomAccessFile("1.txt","rw"); long length=raf.length(); raf.seek(length-1); raf.write("您好,认识你很高兴".getBytes()); raf.close(); } catch(Exception e) { System.out.println(e); } }} 求助 新人一个 大学计算机教师有前途吗? java substring 截取中文需要特殊处理吗? 【求助】关于if循环 Java log4j报错 【菜鸟求助】java接口问题 不知道用java来开发网络在线游戏,各位有兴趣加入开发没? JAVA模拟登录WEB 关于数据转换的问题?急! 请教,这两种写法有什么优缺点? java代码的解释需要帮助! 怎么用正则表达式替换html标签
ifstream readFile("aaa.txt",ios::binary);
int count=0;
char * buf= new char[100]; //这是将来写入文件末尾的内容if(readFile.good())
{
while(!readFile.eof())
{
count++;
readFile.get();
} writeFile.seekp(count-1); //这一句是将文件的指针移动到文件最后
for(int i=0; i<100; i++)
{
writeFile<<buf[i];
writeFile.seekp(++count);
}
}else
cout<<"The File may be crushed or not exist";以上程序最近写过,记得比较清楚;以前用java也写过完全一样的,不过不记得了,原理基本一样吧,都是移动文件指针,然后在输出。
public class MyTest
{
public static void main(String []args)
{
try
{
RandomAccessFile raf=new RandomAccessFile("1.txt","rw");
long length=raf.length();
raf.seek(length-1);
raf.write("您好,认识你很高兴".getBytes());
raf.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}