KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > functions > FileUtils


1 package gnu.kawa.functions;
2 import java.io.*;
3 import gnu.mapping.InPort;
4
5 public class FileUtils
6 {
7   /* #ifndef JAVA2 */
8   // static private int tempFileNumber;
9
/* #endif */
10
11   public static
12   /* #ifndef JAVA2 */
13   // synchronized
14
/* #endif */
15   File createTempFile (String JavaDoc format)
16     throws java.io.IOException JavaDoc
17   {
18     if (format == null)
19       format = "kawa~d.tmp";
20     int tilde = format.indexOf('~');
21     String JavaDoc prefix, suffix;
22     File directory = null;
23     if (tilde < 0)
24       {
25         prefix = format;
26         suffix = ".tmp";
27       }
28     else
29       {
30         prefix = format.substring(0, tilde);
31         suffix = format.substring(tilde+2);
32       }
33     int sep = prefix.indexOf(File.separatorChar);
34     if (sep >= 0)
35       {
36         directory = new File(prefix.substring(0, sep));
37         prefix = prefix.substring(sep+1);
38       }
39     /* #ifdef JAVA2 */
40     return File.createTempFile(prefix, suffix, directory);
41     /* #else */
42     // if (directory == null)
43
// directory = new File(File.separatorChar == '\\' ? "c:\\temp" : "/tmp");
44
// for (;;)
45
// {
46
// File temp = new File(directory,
47
// prefix + (++tempFileNumber) + suffix);
48
// if (! temp.exists())
49
// {
50
// OutputStream out = new FileOutputStream(temp);
51
// out.close();
52
// return temp;
53
// }
54
// }
55
/* #endif */
56   }
57 }
Popular Tags