The following snippet reads your file containing values and converts it into props and from that property obj generate two arrays objs
create a prop obj create a file input stream load the file and then use properties.load(filepath) method this converts the vals in file into props from props u can get two arrays as u require Properties p = new Properties(); FileInputStream fi = null; File f = new File(filepath); String canonicalpath = f.getCanonicalPath(); String fring = path; File file = new File(fring); fis=new FileInputStream(file); p.load(fis); properties.load(file)More Detailed description
import java.io.*; class FileRead { public static void main(String args[]) { try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("textfile.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; String temp[] = new String[2]; String array1[] = new String[6000]; String array2[] = new String[6000]; //Read File Line By Line int i=0; while ((strLine = br.readLine()) != null) { // Print the content on the console // System.out.println (strLine); //Split and assign in the arrays temp = strLine.split("\t"); array1[i] = temp[0]; array2[i] = temp[1]; System.out.println (array1[i] + " " + array2[i]); i++; } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } } Thanks & Regards, Rathish On Wed, Sep 24, 2008 at 8:28 PM, singi1 via java-l < java-l@groups.ittoolbox.com> wrote: > > > > > hi .. > I have a file in the below format > > 1 0.9 > 2 0.7 > 3 2.3 > .. > . > . > . > .. > 6000 0.4 > > here 1 and 0.9 in the first line is seperated by tab... > now i must read this file and store them in 2 arrays.. > (file stored in pc) > i.e., 1,2,3,4.....6000 in one array say array1[](all column-1 values in one > array) > 0.9,0.7,............0.4 in another array say array2[](column-2 values in > another array) > > so that it becomes easy for me to draw a jfreechart for above values.. > i.e., I must draw chart with values in array1[] on x-axis and array2[] > values in y-axis.