Help me to read a txt file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leila
    New Member
    • Nov 2006
    • 1

    Help me to read a txt file

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

    import java.io.File;
    import java.io.IOExcep tion;
    import java.io.RandomA ccessFile;
    import java.util.Date;
    public class ForMe {
    public static void main(String[] args) {
    System.out.prin tln( "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.t xt" );

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

    }
    I create a file named text.txt in E:
    but it said not exist
    I do not know why?!
  • Velhari
    New Member
    • Sep 2006
    • 46

    #2
    Originally posted by leila
    I am new in java. I want to read a simple text file
    I used this code:

    import java.io.File;
    import java.io.IOExcep tion;
    import java.io.RandomA ccessFile;
    import java.util.Date;
    public class ForMe {
    public static void main(String[] args) {
    System.out.prin tln( "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.t xt" );

    // does the file exist
    if ( f.exists() )
    {
    System.out.prin tln( "file exists" );
    }
    else
    System.out.prin tln("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
    Last edited by Velhari; Nov 20 '06, 09:34 PM. Reason: Gramamatical error

    Comment

    • sivadhas2006
      New Member
      • Nov 2006
      • 142

      #3
      Originally posted by leila
      I am new in java. I want to read a simple text file
      I used this code:

      import java.io.File;
      import java.io.IOExcep tion;
      import java.io.RandomA ccessFile;
      import java.util.Date;
      public class ForMe {
      public static void main(String[] args) {
      System.out.prin tln( "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.t xt" );

      // does the file exist
      if ( f.exists() )
      {
      System.out.prin tln( "file exists" );
      }
      else
      System.out.prin tln("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.
      Code:
      Testing File name-getting methods.
      There must exist a TEST file called e:\text.txt
      file exists
      Regards,
      M.Sivadhas.

      Comment

      • sivadhas2006
        New Member
        • Nov 2006
        • 142

        #4
        Originally posted by Velhari
        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.

        Comment

        Working...