import java.io.*;
public class ReadFile
{
public String[] a = new String[1024];
void ReadFile()throws Exception
{
FileReader fr = new FileReader("ming.txt");
BufferedReader br = new BufferedReader(fr);
String str;
int i = 0;
while ((str = br.readLine()) != null)
{
try
{
a[i++] = str.split("\r");//////错误的地方找到String[], 需要String
}
catch (ArrayIndexOutOfBoundsException e)
{
System.err.println(e + ": 1111111 ");
}
catch (NumberFormatException e)
{
System.err.println(e + ": 2222222 ");
}
}
for(i=0;i<a.length;i++)
System.out.println(a[i]);
}
}
主函数在别的位置,这只是一个方法,为什么会出错?
想把下面文件读到一个数组里面,每一个行为数组的一个值ming.txt
1 2 1
1 3 2
1 6 1
5 6 2
2 3 2
2 6 2
解决方案 »
- 数组越界问题求解
- java写教务管理系统SQL2000求高手指点
- 求一个用udp传输大文件的思路!顺带问下udp打洞是什么概念?
- 关于acm的提交方式
- 关于 集合类 和 foreach 的小程序 请大家帮忙
- 我写了个记事本,自己写了个帮助文档 chm的 准备一起压缩在jar里面,点击item怎么打开啊。谢谢
- 为什么这段程序输出是18而不是是17?
- 请问,我自定义了ClassLoader,加载jar文件,可是两个不同的jar文件同时调用了一个 dll 这是程序提示这个dll被调用两次违法,怎么办?
- JB2005与JB9哪个好用点啊
- 寻求图象下载的applet程序
- 布局和设置大小的问题 setBounds和setSize用不起来 望高手指教!
- 覆盖api和过时api问题
public String[][] a = new String[1024][]; 就不报错了。
因为:split(..)返回的是一个String[]。