import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
public class Cc {
public static void main(String args[]){
/*private*/ int len = 0;
File f=new File("d:"+File.separator+"oo.txt");
InputStream in=null;
try{
in=new FileInputStream(f);
}catch(FileNotFoundException e){
e.printStackTrace();
}
byte b[]=new byte[1024];
try{
len=in.read(b);
}catch(IOException e){
e.printStackTrace();
}
try{
in.close();
}catch(IOException e){
e.printStackTrace();
}
System.out.println(new String(b,0,len));
}
}
其中 int len为什么不能用private修饰?
要放也应该把private int len 放在main函数之外,做为类的私有成员变量。
因为private用来修饰成员变量,不能用来修饰局部变量 len是局部变量