This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File Input/Output

 
faiza haris
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 267
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic