List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:Main.java
public static boolean saveBitmap(Bitmap aBmp, String aPath) { if (aBmp == null || aPath == null) { return false; }/*from w ww .j ava2 s. co m*/ FileOutputStream fos = null; ByteArrayOutputStream baos = null; boolean result; try { File file = new File(aPath); if (!file.exists()) { file.createNewFile(); } fos = new FileOutputStream(file); baos = new ByteArrayOutputStream(); aBmp.compress(Bitmap.CompressFormat.PNG, 100, baos); //SUPPRESS CHECKSTYLE fos.write(baos.toByteArray()); baos.flush(); fos.flush(); result = true; } catch (OutOfMemoryError e) { e.printStackTrace(); result = false; } catch (Exception e) { e.printStackTrace(); result = false; } finally { try { if (baos != null) { baos.close(); } if (fos != null) { fos.close(); } } catch (IOException e) { e.printStackTrace(); } } return result; }
From source file:Main.java
public static void logToFile(String filename, String log) { File myFile = new File("/sdcard/SAGETablet/" + filename + ".txt"); try {//from w w w. j a va2 s. c o m if (!myFile.exists()) { myFile.createNewFile(); } FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(log); myOutWriter.close(); fOut.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean saveJPEGBitmap(Bitmap aBmp, String aPath) { if (aBmp == null || aPath == null) { return false; }// ww w .ja va 2 s . c o m FileOutputStream fos = null; ByteArrayOutputStream baos = null; boolean result = false; try { File file = new File(aPath); if (!file.exists()) { file.createNewFile(); } fos = new FileOutputStream(file); baos = new ByteArrayOutputStream(); aBmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); //SUPPRESS CHECKSTYLE fos.write(baos.toByteArray()); baos.flush(); fos.flush(); result = true; } catch (Error e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); result = false; } finally { try { if (baos != null) { baos.close(); } if (fos != null) { fos.close(); } } catch (IOException e) { e.printStackTrace(); } } return result; }
From source file:Main.java
public static void createAccessLog(String accessLog, String fileName) { makeDirectory(getFilesDir());//from w w w . ja v a 2 s .c o m FileOutputStream fos = null; try { File newFile = new File(getFilesDir(), fileName); if (!newFile.exists()) { newFile.createNewFile(); } fos = new FileOutputStream(newFile, false); Writer writer = new OutputStreamWriter(fos); writer.write(accessLog); writer.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.ctt.persistance.StorageFile.java
public static void saveTransaction(Transaction t) throws IOException { try {//from w w w .j a va2s . c o m List<String> list = new ArrayList<String>(); list.add(t.transactionString()); String name_file = Main.prop.getProperty("path_transactions") + "transactions_" + t.getCard_number() + ".csv"; File f = new File(name_file); if (!f.exists()) { f.createNewFile(); } System.out.println("Guardar Transacciones"); FileUtils.writeLines(new File(name_file), list, true); } catch (Exception e) { Main.appendLog("Error: SAVE TRANSACTION: " + e.getMessage()); } }
From source file:Main.java
public static void createFile(String filePath) throws IOException { File file = new File(filePath); File parent = file.getParentFile(); if (!parent.exists()) { parent.mkdirs();/*from w ww. j a v a2 s . c om*/ } file.createNewFile(); }
From source file:Main.java
public static void writeLog(String log) { File file = new File("/sdcard/xh.log"); if (!file.exists()) { try {// ww w .j av a 2 s .c om file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block // e.printStackTrace(); } } BufferedWriter out = null; try { // Create file FileWriter fstream = new FileWriter("/sdcard/xh.log", true); out = new BufferedWriter(fstream); SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm:ss "); String time = sdf.format(new Date(System.currentTimeMillis())); out.append(time); out.append(log); out.append("\r\n\r\n"); } catch (Exception e) {//Catch exception if any } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } }
From source file:mesclasses.util.FileSaveUtil.java
public static File createNewSaveFile(File file) { try {//from w ww .j a va2s . c o m file.createNewFile(); return file; } catch (IOException ex) { LOG.error("Le fichier " + file.getPath() + " ne peut pas tre cr"); return null; } }
From source file:europarl.Cfg.java
public static boolean load_config(String filename) { File f = new File(filename); if (!f.exists()) { try {//from w w w . j a v a 2 s.co m f.createNewFile(); } catch (IOException exc) { log.warn("Can't create the file: " + exc); } } try { cfg = new PropertiesConfiguration(f); cfg.setThrowExceptionOnMissing(false); init_default(); cfg.save(f); return true; } catch (ConfigurationException exc)//error reading: IO, file format... { log.error("Error when loading config: " + exc); return false; } }
From source file:Main.java
public static File createFileInSDCard(String path, String fileName) { File dir = new File(path); try {/*from w ww . j a v a2 s.co m*/ if (!dir.exists() && dir.mkdirs()) { System.out.println("Directory created"); } else { System.out.println("Directory is not created"); } } catch (Exception e) { e.printStackTrace(); } File file = null; try { if (dir.exists()) { file = new File(dir, fileName); file.createNewFile(); } else { } } catch (Exception e1) { e1.printStackTrace(); } return file; }