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:org.apache.camel.loanbroker.webservice.version.LoanBrokerWSTest.java
@BeforeClass public static void setupFreePort() throws Exception { // find a free port number, and write that in the custom.properties file // which we will use for the unit tests, to avoid port number in use problems int port = AvailablePortFinder.getNextAvailable(); String bank1 = "bank1.port=" + port; port = AvailablePortFinder.getNextAvailable(); String bank2 = "bank2.port=" + port; port = AvailablePortFinder.getNextAvailable(); String bank3 = "bank3.port=" + port; port = AvailablePortFinder.getNextAvailable(); String credit = "credit_agency.port=" + port; port = AvailablePortFinder.getNextAvailable(); String loan = "loan_broker.port=" + port; File custom = new File("target/custom.properties"); FileOutputStream fos = new FileOutputStream(custom); fos.write(bank1.getBytes()); fos.write("\n".getBytes()); fos.write(bank2.getBytes());//from w w w. ja v a2s. co m fos.write("\n".getBytes()); fos.write(bank3.getBytes()); fos.write("\n".getBytes()); fos.write(credit.getBytes()); fos.write("\n".getBytes()); fos.write(loan.getBytes()); fos.write("\n".getBytes()); fos.close(); url = "http://localhost:" + port + "/loanBroker"; }
From source file:Main.java
public static void write(Context context, String fileName, String content) { if (content == null) content = ""; try {/*from w w w .j av a2 s . c om*/ FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); fos.write(content.getBytes()); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
private static void saveFileForLocal(String requestPath, String result) { // TODO Auto-generated method stub File file = new File(requestPath); if (!file.exists()) { try {//from w ww . j av a 2s . c o m File parentFile = file.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } file.createNewFile(); FileOutputStream fout = new FileOutputStream(file); byte[] buffer = result.getBytes(); fout.write(buffer); fout.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:Main.java
public static boolean saveFile(String filePath, String str) throws IOException { boolean result = false; if (filePath != null && str != null) { Log.d(TAG, "filePath:" + filePath); File file = new File(filePath); if (file.exists()) { file.delete();//w w w . j a v a2 s .co m } if (file.createNewFile()) { FileOutputStream fos = new FileOutputStream(file.getAbsolutePath()); fos.write(str.getBytes("gb18030")); fos.flush(); fos.close(); result = true; } } return result; }
From source file:Main.java
public static void writeMediaListLastUpdatedTimeToFile(Context context, String listType, String lastUpdatedTime) { // writing to internal private memory FileOutputStream fos = null; try {//from w w w .j av a 2 s . c om fos = context.openFileOutput(listType, Context.MODE_PRIVATE); fos.write(lastUpdatedTime.getBytes()); fos.close(); Log.v(TAG, "Lastupdated time " + lastUpdatedTime + " successfully written to file for listType = " + listType); } catch (Exception exp) { Log.v(TAG, "Failed to write lastUpdated time. exp:" + exp.getMessage()); exp.printStackTrace(); } }
From source file:Main.java
/** * Write content to file fileName in internal storage * @param context : context.//from w w w.j a v a 2 s . com * @param fileName : file name. * @param content : content to back up. */ public static void saveFileToInternalStorage(Context context, String fileName, String content) { FileOutputStream outputStream; try { outputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE); outputStream.write(content.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void saveBookmark(String extractPath, String md5, ArrayList<String> listBookmark) { try {// w ww . j a va 2s.c o m FileOutputStream fos = new FileOutputStream(extractPath + "/bookmark_" + md5, false); for (String str : listBookmark) { fos.write((str + ";").getBytes()); } fos.close(); } catch (IOException ignored) { } }
From source file:Main.java
public static void logScanReport(Context c, String[] logs) { String dir = c.getExternalFilesDir(null).getParent(); try {/* w w w.jav a 2s . co m*/ File file = new File(dir + "/last_scan.log"); boolean append = false; // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } else { /* if(file.length() >= 2097152){ // set log file max size to 2mb append = false; } */ } FileOutputStream fos = new FileOutputStream(file, append); for (String log : logs) { fos.write((log + "\n\n").getBytes()); } fos.close(); } catch (IOException ioe) { Log.e("AndroidUtils", "An exception has occured in logScanReport!"); ioe.printStackTrace(); } }
From source file:Main.java
/** * Write image to internal storage/*from w ww. ja va 2s. com*/ * @param context : Context android. * @param fileName : Image file name. * @param image : Bitmap image format PNG only. */ public static void saveImageToInternalStorage(Context context, String fileName, Bitmap image) { // Convert Bitmap to byteArray ByteArrayOutputStream stream = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); // Open fileOutput with fileName and write byteArray try { FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); if (fos != null) { fos.write(byteArray); fos.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
private static void saveActivity(Activity activity, Class<? extends Activity> clazz) { FileOutputStream fos = null; try {/*from w w w . j av a 2s. co m*/ fos = activity.openFileOutput(FILENAME, Activity.MODE_PRIVATE); fos.write(clazz.getName().getBytes()); } catch (Exception e) { Toast.makeText(activity, "saveActivity: " + e, Toast.LENGTH_LONG).show(); } finally { if (null != fos) try { fos.close(); } catch (Exception e) { } } }