//按字節讀取
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) {
}
}
//按字符讀取
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) {
}
}