Read double input from text file in java -
i have problems regarding reading double input text file
i writing progran can read input fron file contains number this
- 3.4 5.0 12
- 1.3 8.2 6
- 0.8 9.1 2.3
anyone got idea or tips please..??
package test; import java.io.*; import java.util.*; import java.io.ioexception; import java.io.objectoutputstream; import java.io.serializable; import java.io.fileinputstream; import java.io.inputstream; import java.io.objectinputstream; public class readfilevector { public static void main(string[] args){ try{ readdatafromfile(); }catch(ioexception ex){ ex.printstacktrace(); } } public static void readdatafromfile() throws ioexception{ double a, b, c; fileinputstream fis = null; try{ fis = new fileinputstream(new file("d:\\pro1\\vector.inp.txt")); datainputstream dis = new datainputstream(fis); = dis.readdouble(); b = dis.readdouble(); c = dis.readdouble(); system.out.println("double:" + + "; double:" + b + ";double:" + c ); }catch(ioexception ex){ ex.printstacktrace(); }finally{ if(fis != null) fis.close(); } }
} i'm trying this
string stringvalue = new scanner( new file("mydoubles.txt") ).usedelimiter("\\a").next(); // split string whitespace string[] doublesasstrings = stringvalue.split("\\s+"); for( int = 0; < doublesasstrings.length; i++ ) double val = double.parsedouble( doublesasstrings[i] );
you idea.
Comments
Post a Comment