Home arrow static arrow Java Programming [Archive] - Why doesnt this see the file
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Why doesnt this see the file
This topic has 3 replies on 1 page.

Posts:31
Registered: 6/21/04
Why doesnt this see the file  
Jun 25, 2004 7:05 AM



 
This is what I have

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.lang.StringBuffer;

public class Length {

public static void main(String[] args) throws IOException{
//Lookig at blah.txt
File myFile = new File("C:
Documents and Settings\\adam
blah.txt");
if(!myFile.exists()){
System.out.println("File not found");
}
//Printing out Length, lastModified, and returning path to the file
System.out.println("File length - "+ myFile.length());
System.out.println( "File last modified - "+ new Date(myFile.lastModified()).toLocaleString() );//prints last modified
System.out.println("Path to file - " + myFile.getAbsolutePath());//prints Path
StringBuffer buffer = new StringBuffer(myFile.getName().trim());//cuting out white space
if (buffer.length() > 3){
String FileE = buffer.substring(buffer.length()-4);
System.out.println (FileE);//prints file extension

}
}
}

here is the output

File not found
File length - 0
File last modified - Dec 31, 1969 7:00:00 PM
Path to file - C:\Documents and Settings\adam\blah.txt
.txt

why cant it find the file

 

Posts:8,813
Registered: 10/4/00
Re: Why doesnt this see the file  
Jun 25, 2004 7:10 AM (reply 1 of 3)



 
File myFile = new File("C:\\\"Documents and Settings\"\\adam
blah.txt");
 

Posts:31
Registered: 6/21/04
Re: Why doesnt this see the file  
Jun 25, 2004 7:12 AM (reply 2 of 3)



 
think I got it
 

Posts:8,813
Registered: 10/4/00
Re: Why doesnt this see the file  
Jun 25, 2004 7:14 AM (reply 3 of 3)



 
This should work too if it makes thing simpler
File myFile = new File("\"C:
Documents and Settings\\adam\\blah.txt\"");
 
This topic has 3 replies on 1 page.