import java.io.*;
class fileWriteInfo {
void writeInfo()throws IOException{
int size=0;
byte b[]=new byte[6];
FileInputStream fin=new
FileInputStream("c:/java/abc.txt");
System.out.println("yes!");
FileOutputStream fout=new
FileOutputStream("c:/java/abc.txt");
try{
size=fin.available();
System.out.println("file size = "+size);
System.out.println("\nSkip the size :");
fin.skip(size);
System.out.print("Enter 6 chars: ");
for(int i=0;i<6;i++)
b[i]=(byte)System.in.read( );
fout.write(b);
}catch(IOException e){
System.out.print("file IOException!");
}finally{ fout.close( ); }
}
}
public class ReadAndWriteText {
public static void main(String args[])throws Exception {
fileWriteInfo obj=new fileWriteInfo ();
try{
obj.writeInfo();
}
catch(FileNotFoundException e) {
System.out.println("File not found : "+e);
throw e;
}catch(IOException e) {
System.out.println("File not found : "+e);
e.printStackTrace( );}
}
}
我的目的是让他写过一次 第二次再接着第一次的写
但为什么会是 先清空文件再进行写操作呢?