By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,009 Members | 2,866 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,009 IT Pros & Developers. It's quick & easy.

Help me to read a txt file

P: 1
I am new in java. I want to read a simple text file
I used this code:

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;
public class ForMe {
public static void main(String[] args) {
System.out.println( "Testing File name-getting methods." );
System.out
.println(
"There must exist a TEST file called e:\\text.txt" );

// set up handle to file name.
File f = new File( "E:\\text.txt" );

// does the file exist
if ( f.exists() )
{
System.out.println( "file exists" );
}
else
System.out.println("not exist");

}
I create a file named text.txt in E:
but it said not exist
I do not know why?!
Nov 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: 46
I am new in java. I want to read a simple text file
I used this code:

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;
public class ForMe {
public static void main(String[] args) {
System.out.println( "Testing File name-getting methods." );
System.out
.println(
"There must exist a TEST file called e:\\text.txt" );

// set up handle to file name.
File f = new File( "E:\\text.txt" );

// does the file exist
if ( f.exists() )
{
System.out.println( "file exists" );
}
else
System.out.println("not exist");

}
I create a file named text.txt in E:
but it said not exist
I do not know why?!
Hi,
Instead of Double slash you try with single back slash that will hopefull to you.....

With regards,
Velmurugan.H
Nov 20 '06 #2

sivadhas2006
100+
P: 142
I am new in java. I want to read a simple text file
I used this code:

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;
public class ForMe {
public static void main(String[] args) {
System.out.println( "Testing File name-getting methods." );
System.out
.println(
"There must exist a TEST file called e:\\text.txt" );

// set up handle to file name.
File f = new File( "E:\\text.txt" );

// does the file exist
if ( f.exists() )
{
System.out.println( "file exists" );
}
else
System.out.println("not exist");

}
I create a file named text.txt in E:
but it said not exist
I do not know why?!
Hi,

I used the same code whatever you have.

And I got the following output.
Expand|Select|Wrap|Line Numbers
  1. Testing File name-getting methods.
  2. There must exist a TEST file called e:\text.txt
  3. file exists
  4.  
Regards,
M.Sivadhas.
Nov 21 '06 #3

sivadhas2006
100+
P: 142
Hi,
Instead of Double slash you try with single back slash that will hopefull to you.....

With regards,
Velmurugan.H
Hi Velmurugan,

If I used single back slash instead of double back slash it is showing an message

not exist

Regards,
M.Sivadhas.
Nov 21 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.