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
Printable View
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..
Code Java: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.
See how far you can get and then post back when you get stuck.