io问题:一点写,一边读 数据io 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 copy on write.写的时候把原来的文件复制一份,一个文件写一个文件读,然后设置一个刷新时间把写好的文件拿来读,再创建一个新文件写 用ReadOnly方式打开,应该不会影响写还有一种办法就是把原来一直写的文件Copy成另外一个用来读的文件读完之后,把用来读的文件删除或者改名 问题简单。直接给代码吧。public class FileSyncRead { /** * @date Nov 3, 2014 10:27:52 AM<BR/> * @param args */ public static void main(String[] args) throws Exception{ File file = new File("F://sync.txt"); RandomAccessFile raf = new RandomAccessFile(file, "r"); FileDescriptor fd = raf.getFD(); byte[] cache = new byte[1024]; while(true){ fd.sync(); /* long size = raf.length(); System.out.println(size); */ int len = raf.read(cache); if(len > 0){ String str = new String(cache, 0, len); System.out.println(str); } Thread.sleep(2000l); } }} 请各位好心人士帮忙解答!急 SSH怎么配置啊 求一个jsp在线播放falsh(swf)的小例子 ssh验证 请各位大是谈谈eclipse+webwork 做了个程序,有报错,求解 哪位给具体讲讲servlet上下文呀,总是搞晕 关于正则表达式和日志的多个开发包的疑问,如何选择??? 哪位大侠知道csdn左边的目录树是怎么实现的? Apache SOAP的Web Services在Tomcat4.0.4的安装和测试的问题 菜鸟求助,关于SSH配置问题! 携程网三级菜单的实现
读完之后,把用来读的文件删除或者改名
直接给代码吧。public class FileSyncRead { /**
* @date Nov 3, 2014 10:27:52 AM<BR/>
* @param args
*/
public static void main(String[] args) throws Exception{
File file = new File("F://sync.txt");
RandomAccessFile raf = new RandomAccessFile(file, "r");
FileDescriptor fd = raf.getFD();
byte[] cache = new byte[1024];
while(true){
fd.sync();
/*
long size = raf.length();
System.out.println(size);
*/
int len = raf.read(cache);
if(len > 0){
String str = new String(cache, 0, len);
System.out.println(str);
}
Thread.sleep(2000l);
}
}
}