<! --
Code highlighting produced by actipro codehighlighter (freeware)
Http://www.CodeHighlighter.com/
-->PackageCn.edu. dlut. wisdom;
ImportJava. Io.*;
ImportJava. util.*;
Public Class Fileaccess {
Public Static String readalltext (string filename) Throws Ioexception {
Stringbuffer sb = New Stringbuffer ();
Char [] Buf = New Char [ 1024 ];
Bufferedreader br = New Bufferedreader ( New Inputstreamreader ( New Fileinputstream (filename )));
While (Br. Read (BUF) ! = - 1 ){
SB. append (BUF );
}
Return SB. tostring ();
}
Public Static String readalltext (string filename, string encode) Throws Ioexception {
Stringbuffer sb = New Stringbuffer ();
Char [] Buf = New Char [ 1024 ];
Bufferedreader br = New Bufferedreader ( New Inputstreamreader ( New Fileinputstream (filename), encode ));
While (Br. Read (BUF) ! = 0 ){
SB. append (BUF );
}
Return SB. tostring ();
}
Public Static String [] readalllines (string filename) Throws Ioexception {
Arraylist < String > Lines = New Arraylist < String > ();
String S;
Bufferedreader br = New Bufferedreader ( New Inputstreamreader ( New Fileinputstream (filename )));
While (S = BR. Readline ()) ! = Null )
Lines. Add (s );
BR. Close ();
Return Lines. toarray ( New String [] {});
}
Public Static String [] readalllines (string filename, string encode) Throws Ioexception {
Arraylist < String > Lines = New Arraylist < String > ();
String S;
Bufferedreader br = New Bufferedreader ( New Inputstreamreader ( New Fileinputstream (filename), encode ));
While (S = BR. Readline ()) ! = Null )
Lines. Add (s );
BR. Close ();
Return Lines. toarray ( New String [] {});
}
Public Static Void Writealltext (string filename, string text) Throws Filenotfoundexception {
Printwriter pw = New Printwriter ( New Fileoutputstream (filename ));
PW. Print (text );
PW. Flush ();
PW. Close ();
}
Public Static Void Writealltext (string filename, string encode, string text) Throws Filenotfoundexception, unsupportedencodingexception {
Printwriter pw = New Printwriter ( New Outputstreamwriter ( New Fileoutputstream (filename), encode ));
PW. Print (text );
PW. Flush ();
PW. Close ();
}
Public Static Void Writealllines (string filename, string [] lines) Throws Filenotfoundexception {
Printwriter pw = New Printwriter ( New Fileoutputstream (filename ));
For (String S: Lines)
PW. println (s );
PW. Flush ();
PW. Close ();
}
Public Static Void Writealllines (string filename, string encode, string [] lines) Throws Filenotfoundexception, unsupportedencodingexception {
Printwriter pw = New Printwriter ( New Outputstreamwriter ( New Fileoutputstream (filename), encode ));
For (String S: Lines)
PW. println (s );
PW. Flush ();
PW. Close ();
}
Public Static Void Writeobject (string filename, serializable ob) Throws Ioexception {
Objectoutputstream OOS = New Objectoutputstream ( New Fileoutputstream (filename ));
Oos. writeobject (OB );
Oos. Flush ();
Oos. Close ();
}
Public Static Object readobject (string filename) Throws Ioexception, classnotfoundexception {
Objectinputstream OIS = New Objectinputstream ( New Fileinputstream (filename ));
Object ob = Ois. readobject ();
Ois. Close ();
Return Ob;
}
}