my questions regarding the I/O File for the below code are * why does isDirectory() and isFile both return false? isnt a path either a dir or a file only? * how can i test lastModified...as it returns encoded value...and in my case giving me 0 only. * createNewFile is not creating the file specified...anything wrong in code?How does it work? * What is File, Directory by default? read, or write ?
import java.awt.*; import java.io.*; public class TestioFile{ public static void main(String args[]) { try { File f = new File("JCERT" ); File f1 = new File("Eigene Dateien"+ File.separator + "Inpage" +File.separator+ "Images"+ File.separator +"Makkah.jpg" ); File f2 = new File("Eigene Dateien"+ File.separator + "JCERT" +File.separator+ "java cert progs"+ File.separator +"bin"+ File.separator +"TestioFile.java" ); File f3 = new File("Eigene Dateien"+ File.separator + "Inpage" +File.separator+ "Images"+File.separator+ "Forestg.jpg" ); File f4 = new File("Eigene Dateien"+ File.separator + "Inpage" +File.separator+ "internal" );
Salaam! File and Directory are representative classes so if they are not able to find the file or directory given by your path they will return false.
Roopa Bagur
Ranch Hand
Joined: Nov 03, 2000
Posts: 267
posted
0
I think you have to give the complete path in quotes instead of just giving the file name quotes.
Originally posted by faiza haris: my questions regarding the I/O File for the below code are * why does isDirectory() and isFile both return false? isnt a path either a dir or a file only? * how can i test lastModified...as it returns encoded value...and in my case giving me 0 only. * createNewFile is not creating the file specified...anything wrong in code?How does it work? * What is File, Directory by default? read, or write ?
import java.awt.*; import java.io.*; public class TestioFile{ public static void main(String args[]) { try { File f = new File("JCERT" ); File f1 = new File("Eigene Dateien"+ File.separator + "Inpage" +File.separator+ "Images"+ File.separator +"Makkah.jpg" ); File f2 = new File("Eigene Dateien"+ File.separator + "JCERT" +File.separator+ "java cert progs"+ File.separator +"bin"+ File.separator +"TestioFile.java" ); File f3 = new File("Eigene Dateien"+ File.separator + "Inpage" +File.separator+ "Images"+File.separator+ "Forestg.jpg" ); File f4 = new File("Eigene Dateien"+ File.separator + "Inpage" +File.separator+ "internal" );
ok now i tried to get the Date by the object using lastModified() as suggessted, but still its giving errors import java.awt.*; import java.io.*; public class TestioFile4{ public static void main(String args[]) { try{ File f= new File("c:"+File.separator+ "eigene dateien" + File.separator+ "jcert"+ File.separator +"java cert progs" + File.separator + "bin" + File.separator + "Testfilepaths.java"); // f.createNewFile();
Date d= new Date(f.lastModified()); System.out.println(d); }
catch(IOException e){System.out.println(e);} } } Plz help
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.