海
海外流浪汉
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,为什么?怎么解决!谢谢
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,为什么?怎么解决!谢谢