Java ile bir dosya oluşturmak için File.createNewFile() metodu kullanılır. Eğer oluşturulmak istenen dosya zaten mevcut ise
false, işlem başarılı olursa geriye
true değerini dönderir.
import java.io.File;
import java.io.IOException;
/**
*
* @author J4F
*/
public class DosyaOlusturma {
public static void main(String[] args)
{
try
{
File dosya = new File("C:\\test.txt");
if (dosya.createNewFile()) {
System.out.println("Dosya başarıyla Oluşturuldu!");
}
else {
System.out.println("Dosya Zaten Mevcut! İşlem Başarısız!");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
0 yorum:
Yorum Gönder