Results 1 to 2 of 2

Thread: java coding

  1. #1
    Join Date
    Oct 2010

    java coding

    I am working on a java project,i want to sequentially read an ASCII file into an arraylist and then add a method to print out the array. i want to also be able to search through the ASCII file

    can anyone help me with the coding. will realy b much appreciated

  2. #2
    Join Date
    Nov 2008

    Re: java coding

    The first thing is I do not use an array but a class called ArrayList which lets you add elements without first identifying the length (we do not know a prior how many lines you have the file).
    import java.util.ArrayList;
    {Leef class 
    public static void main (String [] arg) { 
    File file = null; 
    FileReader fr = null; 
    ArrayList lines = new ArrayList (); 
    try { 
    file = new File ("C: / file.txt"); 
    String line; 
    fr = new FileReader (file); 
    BufferedReader br = new BufferedReader (fr) 
    while ((line = br.readLine ())!= null) { 
    lineas.add (line); 
    System.out.print ("The Vector is: \ n ");// UNDER THE DATA SHOW 
    for (int j = 0, j <lineas.size () j + +) { 
    line = (String) lineas.get (j); 
    System.out.print (line + "\ n"); 
    } / / END TRY 
    catch (IOException e) { 
    System.out.println (e); 
    finally { 
    try {/ / finally block is always executed, so if the file is closed 
    if (fr! = null) {/ / at the end of the first try, and has an error before, would 
    fr.close (), / / the 1st catch and then would leave, leaving it open. It is convenient 
    } / / Close here, proving that not-for a previous error, as 
    } Catch (IOException e) {/ / not be read or does not exist - null value. 
    System.exit (0);} 
    And if you are trying to read an ASCII file into an arraylist, then following code will help you :
    FileReader myFile = new FileReader ("path");
      BufferedReader buffer = new BufferedReader (myFile);
      String string = file buffer.readLine (); 
      dateString.getBytes ("ASCII");
    FileInputStream my file = new FileInputStream ("path");
     BufferedReader buffer = new BufferedReader (new InputStreamReader (myFile, "ASCII"));
     <Integer> ArrayList list = new ArrayList <Integer> ();
     list.add ( ());

Similar Threads

  1. How to use the pop_heap() in C++ coding
    By Garrick in forum Software Development
    Replies: 4
    Last Post: 05-03-2010, 04:28 PM
  2. java coding for fibonacci series
    By Jagadamba in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 09:44 AM
  3. Code Conventions for JAVA Coding
    By kex in forum Software Development
    Replies: 2
    Last Post: 06-05-2009, 11:23 PM
  4. C++ coding faster?
    By Chandrakant81 in forum Software Development
    Replies: 3
    Last Post: 17-02-2009, 09:51 PM
  5. Problem with C coding
    By SANDESH49 in forum Software Development
    Replies: 2
    Last Post: 02-09-2008, 01:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts