Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-25-2008, 07:50 PM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,691
Rep Power: 5
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default Reading an already opened file
Sometime you are reading a file that is being used by some other process. In that case, you might not be able to read the full contents. The code below attempts again and again until it finds a predefined token at the end of the file.

Code:
	public void parseFile() throws Exception
	{
		ArrayList <String>myArrayList;
		while(true)
		{
		myArrayList = new ArrayList<String>();
		BufferedReader in = new BufferedReader(new FileReader(fileName));
		String fileLine;
		while (( fileLine = in.readLine()) != null) {
                myArrayList.add(fileLine);
		}
		
		if(myArrayList.get(myArrayList.size()-1).equals("ENDFILE")
		{
			in.close();
			break;
		}
		
	} //while
		fileContents = myArrayList;
	}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a File that is opened ravian Advanced Java 6 01-30-2008 03:05 PM
Reading a file mew New To Java 2 12-30-2007 01:23 PM
reading a binary file with a RAF jkurth Advanced Java 2 12-20-2007 08:30 AM
Reading a file for use peachyco New To Java 2 11-27-2007 04:49 AM
Reading from a file leebee New To Java 1 07-23-2007 01:02 PM


All times are GMT +2. The time now is 10:32 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org