List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:Main.java
public static File getTempImage() throws IOException { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File tempFile = new File(Environment.getExternalStorageDirectory(), "temp.jpg"); tempFile.createNewFile(); return tempFile; }// w w w . j a v a2 s . c o m throw new IOException("cannot find any sdcard."); }
From source file:Main.java
public static String createIfNotExist(String path) { File file = new File(path); if (!file.exists()) { try {/*from ww w. jav a 2 s. com*/ file.createNewFile(); } catch (Exception e) { System.out.println(e.getMessage()); } } return path; }
From source file:Main.java
/** * Writes file to external storage and returns the filename. * Writes as a JPEG file./*w w w . j a va2 s . c o m*/ * If you want to convert to a URI you need to prepend file:// * @param b * @param fileName * @return */ static public String saveImageToExternal(Bitmap b, String fileName) { //}, int width, int height) { FileOutputStream fos; String mypath = Environment.getExternalStorageDirectory() + "/" + fileName + ".jpg"; File file = new File(mypath); try { file.createNewFile(); fos = new FileOutputStream(file); // Use the compress method on the BitMap object to write image to the OutputStream b.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } ; return file.toString(); }
From source file:com.thoughtworks.go.util.TestFileUtil.java
public static File createTestFile(File testFolder, String path) throws Exception { File subfile = new File(testFolder, path); subfile.createNewFile(); subfile.deleteOnExit();//from ww w.ja v a2 s .c o m return subfile; }
From source file:Main.java
/** * Save config file./*from ww w . j a v a 2s.c om*/ */ private static void saveConfig(Properties properties) { try { File file = new File(CONFIG_FILE_PATH); if (!file.exists()) file.createNewFile(); FileOutputStream s = new FileOutputStream(file); properties.store(s, ""); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void CreateFile() { File file = new File(mFilePath); if (!file.exists()) { try {// w w w . j av a 2 s . co m file.createNewFile(); } catch (Exception e) { } } }
From source file:Main.java
public static File createFile(String fileName) { File file = new File(fileName); if (!file.exists()) { try {// w w w .j a v a 2s . c om file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } return file; }
From source file:Main.java
public static boolean newFile(String fileName) { File f = new File(fileName); if (!f.exists()) { try {/* w w w . java 2 s . com*/ return f.createNewFile(); } catch (IOException e) { } } return false; }
From source file:Main.java
public static void saveMyBitmap(Bitmap mBitmap) { File f = new File("/sdcard/head.png"); try {//from w ww .jav a 2s . c o m f.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block } FileOutputStream fOut = null; try { fOut = new FileOutputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); try { fOut.flush(); } catch (IOException e) { e.printStackTrace(); } try { fOut.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static File createFileInSDCard(String fileName, String dir) { File file = new File(SDCardRoot + dir + File.separator + fileName); try {/*from w w w. ja v a 2s . c o m*/ file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } updateFile = file; return file; }