Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: help with dis

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with dis

    anyone know how i can store an exsiting text file (file.txt), in an array of object. and then print the content of the file i.e printing the array

    thanks in advance for the code


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,332
    Thanks
    181
    Thanked 829 Times in 772 Posts
    Blog Entries
    5

    Default Re: help with dis

    Please do not post the same question twice in the forums. Your other post has been removed.

    For reading files, see Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)

    For using arrays, sett Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

    If you have more specific questions I'd recommend posting a bit of code to help demonstrate the problem.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: help with dis

    All the code you need can be found here in our Code Snippets forum - Java Code Snippets and Tutorials - Java Programming Forums

    Here is the code for reading a file line by line..

    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
     
    public class Class1 {
     
    public static void main(String[] args) {
     
      try
      {
      FileInputStream in = new FileInputStream("inputFile.txt");
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
     
      while((strLine = br.readLine())!= null)
      {
       System.out.println(strLine);
      }
     
      }catch(Exception e){
       System.out.println(e);
      }
     
     }
    }

    This part of the code prints the current line to the console. You need to add your array code here.

     System.out.println(strLine);

    See how far you can get and then post back when you get stuck.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers