This worked for me.
Mike.
import java.io.*;
public void readFile(){
String line;
URL url=null;
try {
url = new URL (getCodeBase(), "file.txt" );
}
catch (MalformedURLException e ) {
System.out.println("Malformed URL ");
stop();
}
try {
InputStream is=url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null){
// do whatever with line.
}
is.close();
}
catch (IOException e ) {}
}
> Hi,
> Can anyone tell me how to read a file line by line.
> I am confused between so many Readers and writers!!
> Please and urgent
>
> Thanks in advance
you can use BufferedReader and FileReader beacuse it is the easy way to handle file....
class fileRead{
public static void main(String args[]){
BufferedReader br = new BufferedReader(new FileReader("inputFile.txt"));
String str;
while((str = br.readLine())!=-1){
System.out.println("Filecontent:"+str);
}
}
}
Message was edited by:
ggopi
> > while((str = br.readLine())!=-1){
>
> Ow ow ow ow
>
>
> What's up today?
Sorry ya I made a mistake on that line now I cleared that.....
while((str = br.readLine()) != null) {