File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes File Input/Output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "File Input/Output" Watch "File Input/Output" New topic
Author

File Input/Output

faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
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" );

System.out.println(" Path: " + f1.getPath());
System.out.println("Canonical Path: " + f1.getCanonicalPath());
System.out.println("Absolute Path: " + f1.getAbsolutePath());
System.out.println("Absolute Path: " + f1.getName());
System.out.println("Absolute Path: " + f1.getParent());
System.out.println("Absolute Path: " + f1.length());
System.out.println("Absolute Path: " + f2.equals(f1));
System.out.println("Absolute Path: " + f1.isDirectory());
System.out.println("Absolute Path: " + f1.isFile());
System.out.println("Absolute Path: " + f1.isAbsolute());
System.out.println("Absolute Path: " + f3.lastModified());
System.out.println("Absolute Path: " + f4.canWrite());
System.out.println("Absolute Path: " + f3.createNewFile());
System.out.println("Absolute Path: " + f4.mkdir());
System.out.println("Absolute Path: " + f4.exists());

}
catch (IOException e) {}
}
}

thanx alot in advance
asim wagan
Ranch Hand

Joined: Nov 14, 2000
Posts: 62
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
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" );

System.out.println(" Path: " + f1.getPath());
System.out.println("Canonical Path: " + f1.getCanonicalPath());
System.out.println("Absolute Path: " + f1.getAbsolutePath());
System.out.println("Absolute Path: " + f1.getName());
System.out.println("Absolute Path: " + f1.getParent());
System.out.println("Absolute Path: " + f1.length());
System.out.println("Absolute Path: " + f2.equals(f1));
System.out.println("Absolute Path: " + f1.isDirectory());
System.out.println("Absolute Path: " + f1.isFile());
System.out.println("Absolute Path: " + f1.isAbsolute());
System.out.println("Absolute Path: " + f3.lastModified());
System.out.println("Absolute Path: " + f4.canWrite());
System.out.println("Absolute Path: " + f3.createNewFile());
System.out.println("Absolute Path: " + f4.mkdir());
System.out.println("Absolute Path: " + f4.exists());

}
catch (IOException e) {}
}
}

thanx alot in advance

faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
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://aspose.com/file-tools
 
subject: File Input/Output