Android Open Source - BluetoothSppPro Local I O Tools






From Project

Back to project page BluetoothSppPro.

License

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.

Java Source Code

/**
 * //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.");
   *///:~  
}




Java Source Code List

mobi.dzs.android.BLE_SPP_PRO.BaseActivity.java
mobi.dzs.android.BLE_SPP_PRO.BaseCommActivity.java
mobi.dzs.android.BLE_SPP_PRO.actAbout.java
mobi.dzs.android.BLE_SPP_PRO.actByteStream.java
mobi.dzs.android.BLE_SPP_PRO.actCmdLine.java
mobi.dzs.android.BLE_SPP_PRO.actDiscovery.java
mobi.dzs.android.BLE_SPP_PRO.actKeyBoard.java
mobi.dzs.android.BLE_SPP_PRO.actMain.java
mobi.dzs.android.BLE_SPP_PRO.globalPool.java
mobi.dzs.android.bluetooth.BTSerialComm.java
mobi.dzs.android.bluetooth.BluetoothCtrl.java
mobi.dzs.android.bluetooth.BluetoothSppClient.java
mobi.dzs.android.bluetooth.CResourcePV.java
mobi.dzs.android.control.button.ButtonPassListener.java
mobi.dzs.android.control.button.RepeatingButton.java
mobi.dzs.android.storage.CJsonStorage.java
mobi.dzs.android.storage.CKVStorage.java
mobi.dzs.android.storage.CSharedPreferences.java
mobi.dzs.android.util.CHexConver.java
mobi.dzs.android.util.LocalIOTools.java