Reading Data from the Text File

I'm trying to read the Data that is present in abc.txt.

The code that I wrote is given below.

import java.io.*;

import java.util.*;

class test

{

publicstaticvoid main(String args[])

{

StringBuffer sb=new StringBuffer();

int rows=0;

int totalvalues=0;

int columns=0;

String s[];

try

{

//scanner is used to scan the textfile

Scanner sc=new Scanner("abc.txt");

//scan each line in the text file

while(sc.hasNextLine())

{

sb.append(sc.nextLine());

rows++;

}

}

catch(Exception e)

{

System.out.println("Exception"+e);

}

s=(sb.toString()).split("");

totalvalues=s.length;

columns=totalvalues/rows;

System.out.println("rows:"+rows+"Columns"+columns);

double normaldata[][]=newdouble[rows+1][columns+1];

int k=0;

System.out.println("S length is:"+s.length);

try{

for(int i = 1; i < rows; i++)

{

for(int j = 1; j < columns; j++)

{

normaldata[i][j] = Double.parseDouble(s[k]);

k++;

}

}

}

catch(Exception e)

{

System.out.println("Exception internally:"+e);

}

for(int i=1;i<=rows;i++)

{

for(int j=1;j<=columns;j++)

{

System.out.print(normaldata[i][j]+"");

}

System.out.println();

}

}

}

[3218 byte] By [sarath44a] at [2007-11-27 9:11:21]
# 1
Ok, code is fine..but you did not mention what problem you are facing?
vineet.mangala at 2007-7-12 21:56:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...