List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:Main.java
/** * Write data row./*ww w .j a v a2 s . c om*/ * * @param data the data * @param outputPath the output path */ public static void writeDataRow(String data, String outputPath) { File file = new File(outputPath); try { file.createNewFile(); } catch (IOException e1) { e1.printStackTrace(); System.exit(0); } try { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(data); writer.close(); } catch (IOException e) { e.printStackTrace(); System.exit(0); } }
From source file:Main.java
public static void writeFile(String filename, String text) throws Exception { File f = new File(filename); if (!f.exists()) f.createNewFile(); else {//from w w w.j a va2s. c om f.delete(); f.createNewFile(); } BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8")); // new BufferedWriter(new FileWriter(filename, // false),"utf-8"); output.write(text); output.flush(); output.close(); }
From source file:com.hs.mail.util.FileUtils.java
public static boolean createNewFile(File file) { try {/*from w w w . j a va2 s. c om*/ return file.createNewFile(); } catch (IOException e) { return false; } }
From source file:Main.java
/** * (java)write to file/*from ww w . j a va 2s. co m*/ * * @param str * @param path */ public static void writeFile(String str, File file) { FileOutputStream out; try { file.createNewFile(); out = new FileOutputStream(file, false); String infoToWrite = str; out.write(infoToWrite.getBytes()); out.close(); } catch (IOException e) { Log.e("", "write error!"); } }
From source file:Main.java
/** * <pre>/*from ww w .j a v a 2 s . c om*/ * Save byte array to arbitrary file. * </pre> * @param in byte array * @param absolutePath absolute path to destination file */ public static void saveFile(byte[] in, String absolutePath) throws IOException { File file = new File(absolutePath); if (!file.exists()) { file.createNewFile(); } FileOutputStream out = new FileOutputStream(absolutePath); out.write(in); out.close(); }
From source file:Main.java
public static boolean saveReverseTethering() { File reverseTethering = new File(REVERSE_TETHERING_FILE); try {//from w ww.jav a2 s .c o m reverseTethering.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } return true; }
From source file:Main.java
public static void saveMyBitmap(String bitName, Bitmap mBitmap) { File f = new File(bitName); try {/*w ww .j av a 2s .co m*/ f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } FileOutputStream fOut = null; try { fOut = new FileOutputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } mBitmap.compress(Bitmap.CompressFormat.PNG, 90, fOut); try { fOut.flush(); } catch (IOException e) { e.printStackTrace(); } try { fOut.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Write data column./*ww w. j a v a 2 s . c o m*/ * * @param data the data * @param outputPath the output path */ public static void writeDataColumn(List<? extends Number> data, String outputPath) { File file = new File(outputPath); try { file.createNewFile(); } catch (IOException e1) { e1.printStackTrace(); System.exit(0); } try { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); for (Number value : data) { writer.write(value.toString() + "\n"); } writer.close(); } catch (IOException e) { e.printStackTrace(); System.exit(0); } }
From source file:com.yolodata.tbana.testutils.FileTestUtils.java
public static boolean createFileWithContent(String filepath, String content) throws IOException { File f = new File(filepath); if (!f.createNewFile()) return false; PrintWriter pw = new PrintWriter(f); pw.write(content);//from w ww . jav a2 s . co m pw.close(); return true; }
From source file:Main.java
public static File createSDFile(String dir, String fileName) { File file = new File(dir + File.separator + fileName); try {// www .j av a 2 s . c o m file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return file; }