The Artima Developer Community
Sponsored Link

Java Answers Forum
BufferReaders

6 replies on 1 page. Most recent reply: Nov 8, 2002 5:56 AM by Ramu

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
jake

Posts: 83
Nickname: onorok
Registered: May, 2002

BufferReaders Posted: Nov 7, 2002 6:35 PM
Reply to this message Reply
Advertisement
Ok so I am getting a cannot resolve symbol error pointing to new FileReader, what is wrong? I was wondering why I do not have to give it a path in order to find the file. How does it know where the file is? cause all I am giving it is "foo.txt"...a name. Also, this method needs to write each line of a text file to a vector spot. Any suggestions???

import java.io.BufferedReader;
import java.util.Vector;

public class fileRead{
	
	public static Vector fileVector;
	public static String filename_t="";
	BufferedReader br;
	
	void mrT(String filename){
		
	    this.filename_t=filename;
	    br=new BufferedReader(new FileReader(filename) );
	}
};


ramesh

Posts: 1
Nickname: rush
Registered: Nov, 2002

Re: BufferReaders Posted: Nov 7, 2002 6:51 PM
Reply to this message Reply
I think the file u mentioned is not located in the currect working dir.

Ramu

Posts: 29
Nickname: sripoorna
Registered: Oct, 2002

Re: BufferReaders Posted: Nov 7, 2002 7:11 PM
Reply to this message Reply
hi,

u had not imported the FileReader class.
import java.io.FileReader;

use this statement then u program works fine.
when u give u simply foo.txt then it looks for the current directory. If the .txt file is located other than current directroy u have to give to give full path or create a file object with the full path info.

if any quries let me know.

regards
ramu

jake

Posts: 83
Nickname: onorok
Registered: May, 2002

Re: BufferReaders Posted: Nov 7, 2002 8:26 PM
Reply to this message Reply
but what is the current directory and how do you know?

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: BufferReaders Posted: Nov 7, 2002 9:16 PM
Reply to this message Reply
You can get the current directory with this:
System.getProperty( "user.dir" );

jake

Posts: 83
Nickname: onorok
Registered: May, 2002

Re: BufferReaders Posted: Nov 7, 2002 9:41 PM
Reply to this message Reply
ok, so when I do this, it just prints out every other line instead of all 4 lines of the txt file, why is that?


while(br.readLine()!=null){
      System.out.println(br.readLine());
} 

Ramu

Posts: 29
Nickname: sripoorna
Registered: Oct, 2002

Re: BufferReaders Posted: Nov 8, 2002 5:56 AM
Reply to this message Reply
hi,
use the following code

String str1 = br.readLine();
while(str1 != null)
{
System.out.println("read....."+str1);
str1 = br.readLine();
}

Flat View: This topic has 6 replies on 1 page
Topic: Is there a way to distinguish when a factory method creates an object ? Previous Topic   Next Topic Topic: How do I use the breakpoint function in JBuilder7 ?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use