Results 1 to 5 of 5
  1. #1
    hunterdoom is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default help with my homework plsss

    import java.io.*;
    import java.util.Date;

    public class FileOperations {
    public static void main(String[] args) {
    //make sure there is one parameter

    if (args.length != 1) {
    System.err.println("ERROR: must have 1 parameter");
    System.exit(1);
    }
    try {
    File f = new File(args[0]);
    long d;

    System.out.println("getName() =" + f.getName());
    System.out.println("getAbsoluteFile().getName() = "
    + f.getAbsoluteFile().getName());
    boolean exists = f.exists();
    System.out.println("exists() = " + exists);
    if (!exists) {
    System.exit(1);
    }
    System.out.println("canRead() =" + f.canRead());
    System.out.println("canWrite() =" + f.canWrite());
    System.out.println("getPath() =" + f.getPath());
    System.out.println("getAbsolutePath() = " + f.getAbsolutePath());
    System.out.println("getCanonicalPath() = " + f.getCanonicalPath());
    System.out.println("getAbsoluteFile() = " + f.getAbsolutePath());
    System.out.println("toURL() = " + f.toURL());
    System.out.println("toURI() = " + f.toURI());
    System.out.println("getParent() = " + f.getParent());
    System.out.println("isAbsolute() = " + f.isAbsolute());
    boolean isDirectory = f.isDirectory();
    System.out.println("isDirectory() = " + isDirectory);
    System.out.println("isFile() = " + f.isFile());
    System.out.println("isHidden() = " + f.isHidden());
    System.out.println("lastModified() = " + (d =
    f.lastModified())
    + " = " + new Date(d));
    System.out.println("length() = " + f.length());
    if (isDirectory) {
    String[] subfiles = f.list();
    for (int i=0; i<subfiles.length; i++) {
    System.out.println("file in this dir = " +
    subfiles[i]);

    }
    }

    }
    catch (IOException iox) {
    System.err.println(iox);

    }
    }

    }

    hi guys can you help why i run i would get a error like this ERROR: must have 1 parameter
    Java Result: 1
    when i should be getting
    getName() = 1.txt
    getAbsoluteFile().getName() = 1.txt
    exists() = true
    canRead() = true
    canWrite() = true
    getPath() = c:\temp\1.txt
    getAbsoluteFile() = c:\temp\1.txt
    an so on and so forth
    Last edited by hunterdoom; 03-28-2011 at 09:40 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by hunterdoom View Post
    hi guys can you help why i run i would get a error like this ERROR: must have 1 parameter
    Java Result: 1
    You have to supply exactly one command line argument (as the program is trying to tell you). Run it like this:

    Java Code:
    java FileOperations <one argument here>
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    hunterdoom is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    what is the argument about i don't really understand

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Your code says
    Java Code:
    File f = new File(args[0]);
    so you need to provide the name of the File (probably with the full path)

  5. #5
    hunterdoom is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    i am suppose to find the C:\temp file useing the netbeans i think but i don't know how to put in the C:\temp
    Last edited by hunterdoom; 03-28-2011 at 10:30 AM.

Similar Threads

  1. Homework help
    By noobster in forum New To Java
    Replies: 13
    Last Post: 10-31-2010, 10:02 PM
  2. Help me pls It is my homework:(
    By pinar in forum New To Java
    Replies: 3
    Last Post: 10-19-2010, 11:11 PM
  3. help me plsss
    By LeNzKiE in forum New To Java
    Replies: 1
    Last Post: 08-07-2009, 07:35 PM
  4. Please Help with Homework
    By theuser in forum Advanced Java
    Replies: 2
    Last Post: 07-30-2009, 04:37 PM
  5. help with homework
    By pinkdiamondgail in forum Advanced Java
    Replies: 7
    Last Post: 04-07-2009, 02:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •