public class readfile
{ public static void main(String[] args)
{
try
{
File of=new File("./test.txt");
FileInputStream OFIS=new FileInputStream(of);
int nBuffer=-1;
while(-1!=(nBuffer=OFIS.read()))
{
System.out.print((char)nBuffer);
}
}
catch(IOException e)
{
System.out.println(e);
System.exit(1);
}
}
}
test.txt中为一系列的数字,如:32 30 50
20 30 50
想把这些值赋给一个数组a[][]用于计算中,不知道怎么弄?谁弄帮帮我吗?
{ public static void main(String[] args)
{
try
{
File of=new File("./test.txt");
FileInputStream OFIS=new FileInputStream(of);
int nBuffer=-1;
while(-1!=(nBuffer=OFIS.read()))
{
System.out.print((char)nBuffer);
}
}
catch(IOException e)
{
System.out.println(e);
System.exit(1);
}
}
}
test.txt中为一系列的数字,如:32 30 50
20 30 50
想把这些值赋给一个数组a[][]用于计算中,不知道怎么弄?谁弄帮帮我吗?
try {
int[][] a = new int[MAX][3];
FileReader fs = new FileReader("E:\\Eclipse\\Temp\\src\\text.txt");
BufferedReader br = new BufferedReader(fs);
String record = new String();
int i = 0;
while((record = br.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(record);
int j = 0;
while(st.hasMoreTokens())
{
a[i][j] = Integer.parseInt(st.nextToken());
j++;
}
i++;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}