List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:Main.java
public static void createNoMeida(String dir) { File file = new File(dir + ".nomedia"); if (file.exists()) { return;/*from w w w.j a v a2s .c o m*/ } try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static File getFile(Context context, Bitmap sourceImg) { try {//w ww. j a v a 2 s . co m File f = new File(context.getCacheDir(), System.currentTimeMillis() + "temp.jpg"); f.createNewFile(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int options = 100; sourceImg.compress(Bitmap.CompressFormat.JPEG, options, bos); while (bos.toByteArray().length / 1024 > 100) { bos.reset(); options -= 10; sourceImg.compress(Bitmap.CompressFormat.JPEG, options, bos); } byte[] bitmapdata = bos.toByteArray(); FileOutputStream fos = new FileOutputStream(f); fos.write(bitmapdata); fos.flush(); fos.close(); return f; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.vmware.photon.controller.clustermanager.helpers.TestHelper.java
public static void createScriptFile(File scriptDirectory, String scriptContents, String scriptFileName) throws IOException { File scriptFile = new File(scriptDirectory.getAbsolutePath(), scriptFileName); scriptFile.createNewFile(); scriptFile.setExecutable(true, true); FileUtils.writeStringToFile(scriptFile, scriptContents); }
From source file:Main.java
public static boolean copyFile(File sourceFile, File destFile) throws IOException { if (!destFile.exists()) { destFile.createNewFile(); }/*ww w. ja v a2 s . c o m*/ FileInputStream source = null; FileOutputStream destination = null; try { source = new FileInputStream(sourceFile); destination = new FileOutputStream(destFile); destination.getChannel().transferFrom(source.getChannel(), 0, source.getChannel().size()); } catch (Exception e) { // FileLog.e("tmessages", e); return false; } finally { if (source != null) { source.close(); } if (destination != null) { destination.close(); } } return true; }
From source file:Main.java
public static File getFile(String path) throws IOException { String dirPath = path.substring(0, path.lastIndexOf(File.separator)); File dirFile = new File(dirPath); File file = new File(path); if (!dirFile.exists()) dirFile.mkdirs();/*from ww w. j a va 2 s . c o m*/ if (!file.exists()) file.createNewFile(); return file; }
From source file:Main.java
public static File getSaveFile(String folderPath, String fileNmae) { File file = new File(getSavePath(folderPath) + File.separator + fileNmae); try {// w w w .jav a 2s . c o m file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } return file; }
From source file:Main.java
public static File generateFile(String path) { File file = new File(folderName, ".nomedia"); if (!file.exists()) { try {//from w w w .j a va2 s .c o m file.createNewFile(); } catch (IOException e) { e.printStackTrace(); file.mkdir(); } } return new File(folderName(), generateFileName(path)); }
From source file:ZipHelper.java
public static void fileToZip(File file, File zipFile, int compressionLevel) throws Exception { zipFile.createNewFile(); FileOutputStream fout = new FileOutputStream(zipFile); ZipOutputStream zout = null;//from w ww . j a v a 2 s .com try { zout = new ZipOutputStream(new BufferedOutputStream(fout)); zout.setLevel(compressionLevel); if (file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) fileToZip(files[i], zout, file); } else if (file.isFile()) { fileToZip(file, zout, file.getParentFile()); } } finally { if (zout != null) zout.close(); } }
From source file:Main.java
public static void cacheStringToFile(String str, String filename) { File f = new File(filename); if (f.exists()) { f.delete();/* w w w.j a va2 s .c om*/ } try { f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } try { FileOutputStream fos = new FileOutputStream(f, true); fos.write(str.getBytes()); fos.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static int copyFile(String fileDir, String fileName, byte[] buffer) { if (buffer == null) { return -2; }/*from ww w . jav a 2 s . c o m*/ try { File file = new File(fileDir); if (!file.exists()) { file.mkdirs(); } File resultFile = new File(file, fileName); if (!resultFile.exists()) { resultFile.createNewFile(); } BufferedOutputStream bufferedOutputStream = new BufferedOutputStream( new FileOutputStream(resultFile, true)); bufferedOutputStream.write(buffer); bufferedOutputStream.flush(); bufferedOutputStream.close(); return 0; } catch (Exception e) { } return -1; }