Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to read a file in java.

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to read a file in java.

    Hi All,

    I am using Eclipse for java. I have to read a file. Here is my code.

    The below code is in a ButtonHelper.java class:

    public static String ClickButton(String locator){
    try {
    driver.findElement(By.xpath(locator)).click();
    }catch (NoSuchElementException e) {
    e.printStackTrace();
    return "Fail - Click Button Not Found";
    }
    return "Pass";
    }

    In the above code, I have to read the locator from the another file called OR properties file. So how can I do that.

    Help me guys.

    Regards,
    Sudheer


  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to read a file in java.

    In the above code how to fail a test case if a loop is going into exception block.

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How to read a file in java.

    1)Place [code=java] before your code and [/code] after your code.
    2)Read over the FileReader class.
    3)Once you familiarize yourself with that, try using the BufferedReader class.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,199
    Thanks
    49
    Thanked 2,173 Times in 2,146 Posts

    Default Re: How to read a file in java.

    Also you need to post the definitions for all the variables used in the posted code.
    For example what is driver? Or By?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Read input, read file, find match, and output... URGENT HELP!
    By MooseHead in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 3rd, 2012, 11:01 AM
  2. Read and write file in Java
    By waiheng1986 in forum File Input/Output Tutorials
    Replies: 1
    Last Post: March 18th, 2012, 11:54 AM
  3. Java I/O File code; how to read/write file
    By ryu2le in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 18th, 2011, 05:51 PM
  4. [SOLVED] Giving Java the name of a file to be read via command line?
    By lavloki in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: October 14th, 2010, 10:07 AM
  5. Java servlet read file
    By peliukasss in forum Java Servlet
    Replies: 0
    Last Post: April 15th, 2010, 07:02 PM