Results 1 to 5 of 5
Thread: help with my homework plsss
- 03-28-2011, 08:36 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
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 forthLast edited by hunterdoom; 03-28-2011 at 08:40 AM.
- 03-28-2011, 08:40 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 03-28-2011, 09:11 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
what is the argument about i don't really understand
- 03-28-2011, 09:14 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Your code says
so you need to provide the name of the File (probably with the full path)Java Code:File f = new File(args[0]);
- 03-28-2011, 09:27 AM #5
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Homework help
By noobster in forum New To JavaReplies: 13Last Post: 10-31-2010, 09:02 PM -
Help me pls It is my homework:(
By pinar in forum New To JavaReplies: 3Last Post: 10-19-2010, 10:11 PM -
help me plsss
By LeNzKiE in forum New To JavaReplies: 1Last Post: 08-07-2009, 06:35 PM -
Please Help with Homework
By theuser in forum Advanced JavaReplies: 2Last Post: 07-30-2009, 03:37 PM -
help with homework
By pinkdiamondgail in forum Advanced JavaReplies: 7Last Post: 04-07-2009, 01:34 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks