List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:MainClass.java
public static void main(String[] a) throws Exception { File file = new File("c:\\test\\test.txt"); file.createNewFile(); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("ReadOnly.txt"); file.createNewFile(); file.setReadOnly();/* w ww .j a v a 2s. co m*/ if (file.canWrite()) { System.out.println("writable!"); } else { System.out.println("read only!"); } }
From source file:Main.java
public static void main(String[] args) { try {/*from w ww . j a v a 2 s . c om*/ File file = new File("myfile.txt"); if (file.createNewFile()) System.out.println("Success!"); else System.out.println("Error, file already exists."); } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("Writable.txt"); file.createNewFile(); file.setReadOnly();// w w w .j ava2s. co m if (file.canWrite()) { System.out.println("File is writable!"); } else { System.out.println("File is in read only mode!"); } file.setWritable(true); if (file.canWrite()) { System.out.println("File is writable!"); } else { System.out.println("File is in read only mode!"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("test.txt"); // create new file in the system f.createNewFile(); // create new file object from the absolute path File f1 = f.getAbsoluteFile(); System.out.println(f1);/*from w w w . j a v a 2 s. c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C://demo.txt"); boolean blnCreated = false; blnCreated = file.createNewFile(); System.out.println(blnCreated); }
From source file:Main.java
public static void main(String[] args) throws Exception { // create new files File f = new File("test.txt"); // create new file in the system f.createNewFile(); // tests if file exists boolean bool = f.exists(); System.out.println("File exists: " + bool); }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("test.txt"); // tries to create new file in the system boolean bool = f.createNewFile(); System.out.println("File created: " + bool); }
From source file:ReadOnly.java
public static void main(String[] a) throws IOException { File f = new File("f"); if (!f.createNewFile()) { System.out.println("Can't create new file."); return;//from www. ja va2 s .c om } if (!f.canWrite()) { System.out.println("Can't write new file!"); return; } if (!f.setReadOnly()) { System.out.println("Grrr! Can't set file read-only."); return; } if (f.canWrite()) { System.out.println("Most immutable, captain!"); System.out.println("But it still says canWrite() after setReadOnly"); return; } else { System.out.println("Logical, captain!"); System.out.println("canWrite() correctly returns false after setReadOnly"); } }
From source file:com.mysql.servlet.NewClass.java
public static void main(String[] args) { JSONObject headerFile = new JSONObject(); JSONArray listOfAttrs = new JSONArray(); listOfAttrs.add("id" + ""); listOfAttrs.add("name" + ""); listOfAttrs.add("age" + ""); listOfAttrs.add("salary" + ""); listOfAttrs.add("grade" + ""); headerFile.put("Employee", listOfAttrs); try {/*from w w w . j a v a 2 s . c o m*/ // Writing to a file File file = new File("D:\\Employees.json"); file.createNewFile(); FileWriter fileWriter = new FileWriter(file); System.out.println("Writing JSON object to file"); System.out.println("-----------------------"); System.out.print(headerFile); fileWriter.write(headerFile.toJSONString()); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } }