List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:Main.java
public static void saveAccount(Activity act, String account, String psw) { String str = account + "," + psw; Properties localProperties = new Properties(); localProperties.put("account", str); try {// w ww .j a v a2s . c o m File file = new File(act.getFilesDir() + "/accout.cfg"); if (!file.exists()) file.createNewFile(); FileOutputStream localFileOutputStream = act.openFileOutput("account.cfg", Context.MODE_PRIVATE); localProperties.store(localFileOutputStream, ""); localFileOutputStream.close(); } catch (Exception localException) { localException.printStackTrace(); } }
From source file:Main.java
public static void writeToFile(String fileName, byte[] content) { File f = new File(fileName); if (!f.exists()) { try {/*from w w w . j a va2 s . com*/ f.createNewFile(); } catch (Exception e) { } } try { FileOutputStream opt = new FileOutputStream(f, false); opt.write(content, 0, content.length); opt.close(); } catch (Exception e) { } }
From source file:Main.java
public static final void downloadBundle(InputStream is, String saveFilePath) throws IOException { checkDir(saveFilePath);/*from w w w . java 2s . c om*/ File file = new File(saveFilePath, ZIP_BUNDLE_NAME); if (!file.exists()) { file.createNewFile(); } FileOutputStream outputStream = new FileOutputStream(file, false); byte[] buf = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { outputStream.write(buf, 0, len); } outputStream.close(); is.close(); }
From source file:Main.java
public static void printErrorStackTrace(Exception ex) { File f = new File("/sdcard/Hisun/error.log"); try {// w w w . j a v a 2 s .c om if (!f.exists()) { f.createNewFile(); } ex.printStackTrace(new PrintStream(f)); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void createFile(byte[] byteArray) { try {// w w w .jav a 2 s.com File file = new File("C:/Programming/compressedFile"); if (!file.exists()) { file.createNewFile(); } FileOutputStream fos = new FileOutputStream("C://Programming/compressedFile"); fos.write(byteArray, 0, byteArray.length); fos.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void bitmap2file(Bitmap bitmap, String path) { try {/*from w ww . j a v a 2 s.c o m*/ // create a file to write bitmap data File f = new File(path); if (f.exists()) { f.delete(); f.createNewFile(); } ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 30 /* ignored for PNG */, bos); byte[] bitmapdata = bos.toByteArray(); // write the bytes in file FileOutputStream fos = new FileOutputStream(f); fos.write(bitmapdata); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void WriteToFile(String name, Bitmap bitmap, String path) throws IOException { String fString = name.replaceAll("/", "."); File dir = new File("/sdcard/OneBus/user/" + path); if (!dir.exists()) { dir.mkdirs();/*from w w w.j a va2 s . co m*/ } File f = new File("/sdcard/OneBus/user/" + path + "/" + fString + ".jpg"); f.createNewFile(); FileOutputStream fOut = null; try { fOut = new FileOutputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.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:com.wendal.java.dex.decomplier.toolkit.IO_Tool.java
public static void write2File(String rootDir, String package_name, String filename, String data) throws IOException { String tmp[] = package_name.split("[.]"); String tmp_str = rootDir;//from w w w.j av a 2 s. c o m for (int i = 0; i < tmp.length; i++) { tmp_str += "\\"; tmp_str += tmp[i]; } File dir_file = new File(tmp_str + "\\"); dir_file.mkdirs(); File src_file = new File(dir_file.getPath() + "\\" + filename); src_file.createNewFile(); FileUtils.writeStringToFile(src_file, data); }
From source file:Main.java
public static void saveFile(final String fileName, final String str) { try {// ww w .j a va 2 s . c om File f = new File(fileName); if (new File(f.getParent()).exists() == false) { f.getParentFile().mkdirs(); } f.createNewFile(); PrintStream p = new PrintStream(new FileOutputStream(f, false)); p.println(str); p.close(); } catch (Exception e) { e.printStackTrace(); System.err.println(fileName); } }
From source file:Main.java
public static void copyFile(File sourceFile, File destFile) throws IOException { if (!destFile.exists()) { destFile.createNewFile(); }// w w w . j a v a2s . c o m FileChannel source = null; FileChannel destination = null; try { source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); destination.transferFrom(source, 0, source.size()); } finally { closeQuietly(source); closeQuietly(destination); } }