Results 1 to 6 of 6
Thread: Writing and Reading from a file?
- 06-10-2011, 01:33 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
-
- 06-10-2011, 01:54 AM #3
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
i found this code but it reads everything from the file how can i make it read about particular person? Thank You
Java Code: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 ("test.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream (fstream); BufferedReader br = new BufferedReader (new InputStreamReader (in)); String strLine; //Read File Line By Line while ((strLine = br.readLine ()) != null) { // Print the content on the console System.out.println (strLine); } //Close the input stream in.close (); } catch (Exception e) { //Catch exception if any System.err.println ("Error: " + e.getMessage ()); } } }
- 06-10-2011, 02:09 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
If you are reading the lines you can store them and make changes to them. You may want to make a class to represent people, then read a line, create a person object and store the person somewhere. Finally you can make changes to the stored person or write them back to the file.
- 06-10-2011, 02:11 AM #5
If you have multiple blobs of data then read the file one blob at a time, create an object to represent that data and then store your object in a collection. Now you have all your data in memory and you can access and modify it as much as you like. Then when you have finished write it back to the file.
- 06-10-2011, 03:12 AM #6
Similar Threads
-
Reading from .xls file and writing to .csv
By Yatta in forum New To JavaReplies: 1Last Post: 04-09-2011, 04:44 PM -
File reading / writing
By MattBSibley in forum New To JavaReplies: 5Last Post: 04-19-2010, 05:20 AM -
Reading and writing to a file
By jigglywiggly in forum New To JavaReplies: 13Last Post: 03-09-2009, 10:44 AM -
Reading/Writing to file
By Doctor Cactus in forum New To JavaReplies: 2Last Post: 10-28-2008, 02:05 PM -
Help with File reading and writing
By baltimore in forum New To JavaReplies: 1Last Post: 07-31-2007, 06:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks