Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to read the file line by line. It is done with a <code>BufferedReader</code> like this :</p> <pre><code>try { FileInputStream fstream = new FileInputStream("input.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine; int lineNumber = 0; double [] a = null; double [] b = null; // Read File Line By Line while ((strLine = br.readLine()) != null) { lineNumber++; if( lineNumber == 4 ){ a = getDoubleArray(strLine); }else if( lineNumber == 5 ){ b = getDoubleArray(strLine); } } // Close the input stream in.close(); //print the contents of a for(int i = 0; i &lt; a.length; i++){ System.out.println("a["+i+"] = "+a[i]); } } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } </code></pre> <p>Assuming your <code>"a"</code> and<code>"b"</code> are on the fourth and fifth line of the file, you need to call a method when these lines are met that will return an array of <code>double</code> :</p> <pre><code>private static double[] getDoubleArray(String strLine) { double[] a; String[] split = strLine.split("[,)]"); //split the line at the ',' and ')' characters a = new double[split.length-1]; for(int i = 0; i &lt; a.length; i++){ a[i] = Double.parseDouble(split[i+1]); //get the double value of the String } return a; } </code></pre> <p>Hope this helps. I would still highly recommend reading the Java <a href="http://download.oracle.com/javase/tutorial/essential/io/" rel="nofollow">I/O</a> and <a href="http://download.oracle.com/javase/tutorial/java/data/strings.html" rel="nofollow">String</a> tutorials.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload