Back to project page BluetoothSppPro.
The source code is released under:
Apache License
If you think the Android project BluetoothSppPro listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * //from ww w.j ava2s .c o m */ package mobi.dzs.android.util; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; /** * ??IO???? * @author JerryLi(hzjerry@gmail.com) * @version 1.0 * @date 2010-06-25 */ public class LocalIOTools{ /** * ????????????? * * @param String path ???? * @return String ???????????????? */ public static String LoadFromFile(String path){ StringBuffer sbOutBuf = new StringBuffer(); String read; BufferedReader bufread; try { File fhd = new File(path); // ?????????? bufread = new BufferedReader(new FileReader(fhd)); // ???? /* ?????????? */ while ((read = bufread.readLine()) != null) sbOutBuf.append(read); bufread.close(); }catch (Exception d){ // System.out.println(d.getMessage()); return null; } return sbOutBuf.toString(); // ?????? } /** * byte????????? * ???????????? * * @param String path ????(???????\??????) * @param String sFile ????? * @param byte[] bData ?????????? * * @return boolean * @see android.permission.WRITE_EXTERNAL_STORAGE */ public static boolean appendByte2File(String sPath, String sFile, byte[] bData){ try { /*??????????*/ File fhd = new File(sPath); // ?????????? if (!fhd.exists()) if (!fhd.mkdirs())//?????????? return false; //????????? /*??????????*/ fhd = new File(sPath +"\\"+ sFile); // ?????????? if (!fhd.exists()) if (!fhd.createNewFile()) //?????????? return false; //????????? //????????? FileOutputStream fso = new FileOutputStream(fhd, true); fso.write(bData); fso.close(); return true; }catch (Exception d){ // System.out.println(d.getMessage()); return false; } }/*Output: if (LocalIOTools.appendByte2File("F:/temp", "javatest.txt", "this is test.\r\nbuf write".getBytes())) System.out.println("write ok."); else System.out.println("write fail."); *///:~ /** * byte???????? * ?????????? * * @param String path ????(???????\??????) * @param String sFile ????? * @param byte[] bData ?????????? * * @return boolean * @see android.permission.WRITE_EXTERNAL_STORAGE */ public static boolean coverByte2File(String sPath, String sFile, byte[] bData){ try { /*??????????*/ File fhd = new File(sPath); // ?????????? if (!fhd.exists()) if (!fhd.mkdirs())//?????????? return false; //????????? /*??????????*/ fhd = new File(sPath +"/"+ sFile); // ?????????? if (fhd.exists()) fhd.delete(); //??????? //????????? FileOutputStream fso = new FileOutputStream(fhd); fso.write(bData); fso.close(); return true; }catch (Exception d){ System.out.println(d.getMessage()); return false; } }/*Output: if (LocalIOTools.appendByte2File("F:/temp", "javatest.txt", "this is test.\r\nbuf write".getBytes())) System.out.println("write ok."); else System.out.println("write fail."); *///:~ }