Source code for create file. Example : text.txt, sample.dat, etc..
import java.io.File;
import java.io.IOException;
public class MakeFile {
public static void main(String[] args) {
File myFile = new File("myJava.java"); //change this filename
try {
myFile.createNewFile();
} catch (IOException e) {
System.out.println("Cannot created.");
}
}
public String createFile(String fileName) {
File myFile = new File(fileName);
try {
myFile.createNewFile();
return "0:OK";
} catch (IOException e) {
System.out.println(e.getMessage());
return "1:Not OK";
}
}
}
save as MakeFile.java
No comments:
Post a Comment