List of usage examples for java.io FileOutputStream write
public void write(byte b[]) throws IOException
b.length
bytes from the specified byte array to this file output stream. From source file:de.unimannheim.spa.process.util.FileUtils.java
public static File convertMultipartToFile(MultipartFile multipartFile) throws IllegalStateException, IOException { File convertedFile = new File(multipartFile.getOriginalFilename()); FileOutputStream fos = new FileOutputStream(convertedFile); fos.write(multipartFile.getBytes()); fos.close();/*from www.j av a2s . c o m*/ return convertedFile; }
From source file:Main.java
public static File save2File(String savePath, String saveName, String crashReport) { try {/*from ww w .j a v a2s . co m*/ File dir = new File(savePath); if (!dir.exists()) dir.mkdir(); File file = new File(dir, saveName); FileOutputStream fos = new FileOutputStream(file); fos.write(crashReport.toString().getBytes()); fos.close(); return file; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static void saveThumbnail(String filePath, Bitmap bitmap) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); // you can create a new file name "test.jpg" in sdcard folder. File f = new File(filePath); try {//www .ja va 2 s .com f.createNewFile(); // write the bytes in file FileOutputStream fo = new FileOutputStream(f); fo.write(bytes.toByteArray()); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void compressWithQuality(Bitmap image, String outPath, int maxSize) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 20, os); while (os.toByteArray().length / 1024 > 1024) { os.reset();// w ww . jav a 2 s .c o m image.compress(Bitmap.CompressFormat.JPEG, 20, os); } ByteArrayInputStream bi = new ByteArrayInputStream(os.toByteArray()); BitmapFactory.decodeStream(bi); FileOutputStream fi = new FileOutputStream(outPath); fi.write(os.toByteArray()); fi.flush(); fi.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 av a2s .c o m } 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 void save(String filename, String content, Context context) throws Exception { FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_PRIVATE); outStream.write(content.getBytes()); outStream.close();/*from w w w .j a va2 s . c om*/ }
From source file:Main.java
private static void writeLog(String file) throws Exception { FileOutputStream in = new FileOutputStream("/usr/local/software/importlog.txt", true); in.write((file + "\n").getBytes()); }
From source file:Main.java
public static void bitmap2file(Bitmap bitmap, String path) { try {//from w w w . j a v a2 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:com.aqnote.shared.cryptology.cert.util.PrivateKeyFileUtil.java
public static void writeKeyFile(String b64Key, String keyfile) throws IOException { if (StringUtils.isBlank(b64Key) || StringUtils.isBlank(keyfile)) { return;//from w ww . j a v a2 s. com } FileOutputStream fos2 = new FileOutputStream(keyfile); fos2.write(b64Key.getBytes()); fos2.flush(); fos2.close(); }
From source file:Main.java
/** * Write a string value to the specified file. * @param filename The filename/*w w w . jav a 2 s .c o m*/ * @param value The value */ public static void writeValue(String filename, String value) { try { FileOutputStream fos = new FileOutputStream(new File(filename)); fos.write(value.getBytes()); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }