Java Reference
In-Depth Information
---/tmp/id---
Canonical name /tmp/id
Parent directory: /tmp
File is readable.
File is writable.
Last modified October 8, 1999 1:01:54 PM PDT
File size is 0 bytes.
---/autoexec.bat---
file not found
$
A typical Unix system has no autoexec.bat file. And Unix filenames (like those on a Mac)
can consist of upper- and lowercase characters: what you type is what you get.
Creating a File
Problem
You need to create a new file on disk, but you don't want to write into it.
Solution
Use a java.io.File object's createNewFile() method.
Discussion
You could easily create a new file by constructing a FileOutputStream or FileWriter (see
Opening a File by Name ) . But then you'd have to remember to close it as well. Sometimes
you want a file to exist, but you don't want to bother putting anything into it. This might be
used, for example, as a simple form of interprogram communication: one program could test
for the presence of a file and interpret that to mean that the other program has reached a cer-
tain state. Here is code that simply creates an empty file for each name you give:
public
public class
class Creat
Creat {
public
public static
static void
void main ( String [] argv ) throws
throws IOException {
Search WWH ::




Custom Search