Re: creating/copying files..
- From: Carl <_Nospam_@xxxxxxxxxxxx>
- Date: Wed, 28 Dec 2005 22:47:23 GMT
Roedy Green wrote:
File by itself won't let you create an empty file. You can create with FileOutputStream and writing no bytes. Just close.
Are you sure about that? It seems to work just fine for me.
//code import java.io.File; import java.io.IOException;
public class Test {
private void makeFile(){
File file = new File(System.getProperty("user.home"),
"testfile.txt");
System.out.println("Checking existence of file: "
+ file.toString());
if (file.exists()) {
System.out.println("Found!");
} else {
System.out.println("File not found!" +
"\nCreating file.");
try {
if (file.createNewFile()) {
System.out.println("File created!");
}
} catch (IOException e) {
System.out.println("Unable to create file!");
e.printStackTrace();
}
}
}
public static void main(String[] args){
Test t = new Test();
t.makeFile();
System.out.println("Done.");
System.exit(0);
}} // end code
Carl. .
- Follow-Ups:
- Re: creating/copying files..
- From: Roedy Green
- Re: creating/copying files..
- References:
- creating/copying files..
- From: Frances
- Re: creating/copying files..
- From: Roedy Green
- Re: creating/copying files..
- From: Frances
- Re: creating/copying files..
- From: Roedy Green
- creating/copying files..
- Prev by Date: Re: creating/copying files..
- Next by Date: Re: creating/copying files..
- Previous by thread: Re: creating/copying files..
- Next by thread: Re: creating/copying files..
- Index(es):
Relevant Pages
|
|