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 occurredSecurityException
- If a security manager exists and its
method denies write access to the fileSecurityManager.checkWrite(java.lang.String)
- 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
반응형
'UNIX&LINUX > 쉘스크립트' 카테고리의 다른 글
쉘스크립트 기본 case문 select문 (0) | 2014.07.14 |
---|---|
쉘스크립트 기본 while문 until문 (0) | 2014.07.14 |
소소한 쉘스크립트 Tip 하나 (0) | 2014.07.14 |
쉘스크립트 기초 (0) | 2014.07.14 |
쉘스크립트 참조 블로그 (0) | 2014.05.16 |
BASH 쉘스크립트 기초 - 변수 & 연산 (0) | 2014.05.13 |
쉘 스크립트 레드마인 (0) | 2014.05.13 |
[OS][LINUX][SHELL]쉘 스크립트 (0) | 2014.05.13 |