// Display the content of the opened file
Void readfile (string path)
{
Try
{
File file = new file (PATH );
Inputstream FS = new fileinputstream (File );
Bufferedreader BR;
// Byte [] buffer = new byte [fs. Available ()];
Byte [] buffer = new byte [3];
FS. Read (buffer );
FS. Close ();
String STR = "";
Int size = (INT) file. Length ();
Int charread = 0;
Char [] content = new char [size];
// Byte [] content = new byte [size];
// Determine the file encoding
If (buffer [0] =-17 & buffer [1] =-69 & buffer [2] =-65)
{
BR = new bufferedreader (New inputstreamreader (
New fileinputstream (file), "UTF-8"); // encoding conversion
While (Br. Ready ())
{
Charread + = Br. Read (content, charread, size-charread );
}
BR. Close ();
STR = new string (content, 0, charread );
Text. settext (STR );
} Else
{
BR = new bufferedreader (New inputstreamreader (
New fileinputstream (file), "GBK"); // encoding conversion
While (Br. Ready ())
{
Charread + = Br. Read (content, charread, size-charread );
}
BR. Close ();
STR = new string (content, 0, charread );
Text. settext (STR );
}
} Catch (ioexception E)
{
System. Out. println ("file reading error ");
}
}