下面的两个功能对吗?为什么老是进入catch ()里?? (源代码太长)try{
//计算行数
File fis = new File ("C:\\myfile.txt");
BufferedReader dis = new BufferedReader(fis);
while(dis.readLine()!=null){
enter_count++;
}
//将每一行符值给一个字符串
fis = new FileInputStream("C:\\myfile.txt");//由于上面的dis.readLine()将文件读完了,所以要从新初始化一遍
dis = new DataInputStream(fis);
String s[] = new String[enter_count];
i = 0;
while(dis.available()!=0){
s[i] = dis.readLine();
s1[i]=s[i];
i++;
}
dis.close();
}catch(Exception e){
System.err.println("File input error");
}
}
}
//计算行数
File fis = new File ("C:\\myfile.txt");
BufferedReader dis = new BufferedReader(fis);
while(dis.readLine()!=null){
enter_count++;
}
//将每一行符值给一个字符串
fis = new FileInputStream("C:\\myfile.txt");//由于上面的dis.readLine()将文件读完了,所以要从新初始化一遍
dis = new DataInputStream(fis);
String s[] = new String[enter_count];
i = 0;
while(dis.available()!=0){
s[i] = dis.readLine();
s1[i]=s[i];
i++;
}
dis.close();
}catch(Exception e){
System.err.println("File input error");
}
}
}
解决方案 »
- java父容器监听问题。
- 两个jvm,可以互相操纵对方的对象吗
- 求教java / C 通讯时aocketaddr_in 如何转换的问题
- 一道题 请达人指教~~~~~~~~~~~~~
- 请教 边缘点的判断问题
- 有没有什么控件可以列表显示小的.gif图片阿,JList好像不行,不知道什么能行。
- JList的焦点问题!?!
- 想做一个监控程序,每隔一段时间(比方说10秒)去扫描数据库,读取最新的数据,谁能给我一点思路?分不够,再开就是。
- URLConnection.setRequestProperty(String key, String value)做了什么?
- 幫我看一下这个程序, java 调用sqlserver存储过程,那里出错了.
- null异常?
- 两个基础的问题(类访问权限&自动装箱)
int enter_count = 0;
try {
// 计算行数
FileInputStream fis = new FileInputStream("abc.txt");
BufferedReader dis = new BufferedReader(new InputStreamReader(fis));
while (dis.readLine() != null) {
enter_count++;
}
System.out.println(enter_count);
// 将每一行符值给一个字符串
fis = new FileInputStream("abc.txt");// 由于上面的dis.readLine()将文件读完了,所以要从新初始化一遍
DataInputStream ds = new DataInputStream(fis);
String s[] = new String[enter_count];
int i = 0;
while (ds.available() != 0) {
System.out.println(ds.readLine());
}
dis.close();
} catch (Exception e) {
e.printStackTrace();
System.err.println("File input error");
}
这样是可以的...没错啊...语法错误吧? @_@