源代码在这里:
import java.io.*;public class TestFileInputStream { public static void main(String[] args) throws IOException {
int b = 0;
FileInputStream in = null;
try {
in = new FileInputStream("e:/java/1.txt");
} catch (FileNotFoundException e) {
System.out.println("找不到指定文件!");
System.exit(0);
e.printStackTrace();
}
long num = 0;
while((b=in.read()) !=-1){
System.out.print((char)b);
num++;
} }}
请教一下,为什么如果事先不声明 in,也就是说直接在try里面声明FileInputStream in = new FileInputStream("xx")
的话,下面在 while里面会找不到in?
import java.io.*;public class TestFileInputStream { public static void main(String[] args) throws IOException {
int b = 0;
FileInputStream in = null;
try {
in = new FileInputStream("e:/java/1.txt");
} catch (FileNotFoundException e) {
System.out.println("找不到指定文件!");
System.exit(0);
e.printStackTrace();
}
long num = 0;
while((b=in.read()) !=-1){
System.out.print((char)b);
num++;
} }}
请教一下,为什么如果事先不声明 in,也就是说直接在try里面声明FileInputStream in = new FileInputStream("xx")
的话,下面在 while里面会找不到in?
解决方案 »
- Java控制台读取字符的问题
- 关于ArrayList的 E remove(int index) 和boolean remove(Object o)方法
- 求一Jakarta-ORO正则表达式
- 小妹请教JSP编程高手,紧急紧急!!
- Java 类与类(class文件)调用问题,请高手解决
- 哪位同仁知道天津地区的软件业情况如何,给兄弟指点指点
- 各位老师,嘿嘿,不好意思,俺想在我的网站链接上,卖弄一下STRUTS技术,请看,感谢帮忙
- 谁能解释一下useBean中的beanName从文件的具体做法?
- 请问各位谁知道JBuilder7的注册解密方法,我没有序列号,也没有解密文件
- Java循环查询数据库
- 关于GUI编程中JMenu的一个小问题!在线等,请高手赐教!
- 視頻轉換軟件
import java.io.*;public class TestFileInputStream { public static void main(String[] args) throws IOException {
int b = 0;
try {
FileInputStream in = new FileInputStream("e:/java/1.txt");
} catch (FileNotFoundException e) {
System.out.println("找不到指定文件!");
System.exit(0);
e.printStackTrace();
}
long num = 0;
while((b=in.read()) !=-1){
System.out.print((char)b);
num++;
} }}
try..catch处的自然不能访问咯。。