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 2 of 2

Thread: Need help with Java's Paths class

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

    Default Need help with Java's Paths class

    Hi, everybody! I'm a real newbie to Java programming and I'm sure I've come to the right place for help. Anyways....I have an assignment that reads like so:

    Create two files using any word processing program or text editor. Write an application that determines whether the two files are located in the same folder. Save the file as SameFolder. java.


    I'm assuming that I need to construct some sort of IF statement utilizing the public boolean exists() method. But whenever I try to use that method or the isDirectory() method the program won't compile and I get a "cannot find symbol" error right at the exists() and isDirectory() methods. Here's what I have so far:

    import java.nio.file.*;
    import static java.nio.file.AccessMode.*;
    import java.io.IOException;

    public class FileTest
    {
    public static void main(String[] args)
    {


    Path path = Paths.get("C:\\Program Files\\Java\\FirstFile.txt");
    Path bPath = Paths.get("C:\\Program Files\\Java\\SecondFile.txt");

    if(Path.exists(Path path) && Path.exists(Path bPath)
    {
    System.out.println("Files exist in same folder");
    }

    }



    }


    Please note that I have to use the new Paths class. Statements like "File bPath = new File(file1)" cannot be used. Thanks in advance


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need help with Java's Paths class

    You have quite a few syntax errors in there. I recommend you take this one step at a time, and consult the API every time you call a method: Java Platform SE 6
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Euler Paths with dfs algorithm problem
    By claudio.r in forum Algorithms & Recursion
    Replies: 18
    Last Post: March 22nd, 2012, 04:39 PM
  2. Replies: 3
    Last Post: April 13th, 2011, 03:30 PM
  3. Whats wrong with Java's Private Membership
    By CandorZ in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 25th, 2010, 05:46 AM
  4. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM
  5. Probelm in Path and Paths Classes
    By neo_2010 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: July 14th, 2009, 10:39 AM