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
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.
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
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.
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.