Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading values from txt file

807605Aug 22 2007 — edited Aug 24 2007
Hi,
I was hoping someone could help me. I am trying to read these values
3.182, 0.02734, 1126.0, 4.998E-4, 0.01581, 11.0, -150.3, 10.46, 3.735, 0.8474, -0.4854, 0.7866, 1.475, 0.9439, 0.769, 0.1846, 0.07678, -0.9491, -1.236, -0.9908, 0.5265, -0.27, 0.3569, -0.09167, 0.1295, -0.04507, 0.1029, -0.03005, 0.0, 0.03752, 0.001151, 0.2935, 74.84, 19080.0, 6.086, etc
from a txt file. I have done some coding on it but dont seem to be getting the desired results. I want to take these values and put them in a 2D array.. but its not doing it. Can you see any mistakes i have done please ?
public double[][] readFile(){
		
 		double[][] dArray = new double[164][37];
 		int a  = 0;
        int b = 0;  
       
		      try
		      {  FileReader fin = new FileReader("myFile.txt");
		            	BufferedReader in = new BufferedReader(fin);
		         		String line;
		         	
		         		while((line = in.readLine()) != null){
                            String[] value = line.split(", ");
                        
		         		
                            for (int x=0; x<value.length ; x++){
                            	System.out.println("a:  "+a+" || b: "+b);
                               	 if (b == 37) {
     		         		    	 a = a++;  
     		         		      } else 
     		         		     {
     		         		    	 dArray[a] = Double.parseDouble(value[x]);
System.out.println("value: "+dArray[1][1]);
b++;
}
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2007
Added on Aug 22 2007
17 comments
141 views