Read by Byte
public static void Readbybytes (String URL) {
File File = new file (URL);
InputStream in = null;
try {
in = new FileInputStream (file);
int temp;
while (temp = In.read ())! =-1) {
SYSTEM.OUT.PRINTLN (temp);
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
Read by character
public static void Readbychar (String URL) {
File File = new file (URL);
Reader read = null;
StringBuffer buff = new StringBuffer ();
char[] arr = new char[1024];
int cha=0;
try {
Read =new InputStreamReader (new FileInputStream (file), "Utf-8");
while ((Cha=read.read (arr))!=-1) {
Buff.append (New String (Arr,0,cha));
}
System.out.println (Buff.tostring ());
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
Read by row
public static void Readbyline (String URL) {
File File = new file (URL);
try {
InputStreamReader in = new InputStreamReader (new FileInputStream (file), "UTF-8");
BufferedReader buff = new BufferedReader (in);
String text =null;
while ((Text = Buff.readline ())!=null) {
System.out.println (text);
}
} catch (FileNotFoundException e) {
} catch (Unsupportedencodingexception e) {
} catch (IOException e) {
}
}
Java reads the local text file