怎样以追加的方式写出文件? 用write??? 请看一下代码? ( 积分: 0 )

  • 主题发起人 海外流浪汉
  • 开始时间

海外流浪汉

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样以追加的方式写出文件? 用write?? 请看一下代码?
package javaio;
import java.io.*;
public class WriteFile{
public static void main(String args[]){
try{
//CreateFile = "d:/myout.data";
String fileName = "d:/myout.data";//指定文件名
File file = new File(fileName);
FileOutputStream out = new FileOutputStream(file);//建立输出流
byte[] b = new byte[1024];
String str = "Nice to see you again!";
b = str.getBytes();//String转化为byte[]
long l = file.length();
//System.out.println(toString());
out.write(b,(int) l,10);//写入文本内容 }
catch(IOException e){
System.out.println(e.toString());
}
}
}
用debug调试试发现l=0,为什么?怎么解决!谢谢
 
怎样以追加的方式写出文件? 用write?? 请看一下代码?
package javaio;
import java.io.*;
public class WriteFile{
public static void main(String args[]){
try{
//CreateFile = "d:/myout.data";
String fileName = "d:/myout.data";//指定文件名
File file = new File(fileName);
FileOutputStream out = new FileOutputStream(file);//建立输出流
byte[] b = new byte[1024];
String str = "Nice to see you again!";
b = str.getBytes();//String转化为byte[]
long l = file.length();
//System.out.println(toString());
out.write(b,(int) l,10);//写入文本内容 }
catch(IOException e){
System.out.println(e.toString());
}
}
}
用debug调试试发现l=0,为什么?怎么解决!谢谢
 
java 不知道,
append有吗?
 
可能使你根本就没读过这个文件,你怎么知道他有多长呢。
 
用 RandowAccessFile
 
顶部