728x90
반응형

//로그 파일 생성
        gw_file.createNewFile();      
        // file name 이 유효하던 안하던  파일을 만들어 준다. crateNewFile()
        exception_file.createNewFile();


http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#createNewFile
()
createNewFile

public boolean createNewFile()
                      throws IOException
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.

Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.

Returns:
true if the named file does not exist and was successfully created; false if the named file already exists
Throws:
IOException - If an I/O error occurred
SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
Since:
1.2


좋은 소스~


package aaaaa;
import java.io.*;
import java.util.Date;
public class TestDataStream
{
 public static void main(String args[])
 {
      String myStr = new String("Grabage in, garbage out");
      String dirName = "c:/Mydata";
 
      try
      {
    File dir = new File(dirName);
    if(!dir.exists())
    {
     dir.mkdir();
    }
    else
    {
     if(!dir.isDirectory())
     {
         System.err.println(dirName + " is not a directory");
         return ;
     }
   
     File aFile = new File(dir, "data.txt");
     aFile.createNewFile();
   
     DataOutputStream myStream = new DataOutputStream(
     new FileOutputStream(aFile));
     myStream.writeChars(myStr);
   }
 
      }catch(IOException e){
   System.out.println("IOException thrown : " + e);
      }
 }
}

또 다른 좋은 소스 (안타깝게 못퍼게해서.ㅠ.ㅠ 스크린샷 찍었다 ㅋㅋㅋ)
사용자 삽입 이미지
728x90
반응형
블로그 이미지

nineDeveloper

안녕하세요 현직 개발자 입니다 ~ 빠르게 변화하는 세상에 뒤쳐지지 않도록 우리모두 열심히 공부합시다 ~! 개발공부는 넘나 재미있는 것~!

,