temp = (char) bytearray[i];
result += temp;
}
return result;
}
//java 合并两个byte数组
public byte[] byteMerger(byte[] byte_1, byte[] byte_2){
byte[] byte_3 = new byte[byte_1.length+byte_2.length];
System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
return byte_3;
}
//删除文件
public void DeleteFile(File file) {
if (file.exists() == false) {
Log.e("www","DeleteFile not exists!!!");
return;
} else {
if (file.isFile()) {
file.delete();
Log.e("www","DeleteFile 1 ok!!!");
return;
}
if (file.isDirectory()) {
File[] childFile = file.listFiles();
if (childFile == null || childFile.length == 0) {
file.delete();
return;
}
for (File f : childFile) {
DeleteFile(f);
}
file.delete();
Log.e("www","DeleteFile ok!!!");
}
}
}
/**
* 复制单个文件
* @param oldPath String 原文件路径 如:c:/fqf.txt
* @param newPath String 复制后路径 如:f:/fqf.txt
* @return
*/
public void copyFile(String oldPath, String newPath) {
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件不存在时
InputStream inStream = new FileInputStream(oldPath);
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
while ( (byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字节数 文件大小
System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
inStream.close();
fs.close();
}
}
catch (Exception e) {
System.out.println("复制单个文件操作出错");
e.printStackTrace();
}
}
//write data to file in SD
public void writeFileSdcardFile(String fileName,String write_str) throws IOException{
try{
FileOutputStream fout = new FileOutputStream(fileName);
byte [] bytes = write_str.getBytes();
fout.write(bytes);
fout.close();
}
catch(Exception e){
e.printStackTrace();
}
}
//read data from SD
public String readFileSdcardFile(String fileName) throws IOException{
String res="";
try{
FileInputStream fin = new FileInputStream(fileName);
int length = fin.available();
byte [] buffer = new byte[length];
fin.read(buffer);
res = EncodingUtils.getString(buffer, "UTF-8");
fin.close();
}
catch(Exception e){
e.printStackTrace();
}
return res;
}
//2 read data from SD//161020
public byte [] readByteSdcardFile(String fileName) throws IOException{
//String res="";
try{
FileInputStream fin = new FileInputStream(fileName);
int length = fin.available();
byte [] buffer = new byte[length];
fin.read(buffer);
//res = EncodingUtils.getString(buffer, "UTF-8");
fin.close();
return buffer;
}
catch(Exception e){
e.printStackTrace();
}
return null;
}
//run linux cmd
String do_exec(String cmd) {
String s = "/n";
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
s += line + "/n";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//text.setText(s);
return cmd;
}
public static String str2HexStr(String str) {
char[] chars = "0123456789ABCDEF".toCharArray();
StringBuilder sb = new StringBuilder("");
byte[] bs = str.getBytes();
int bit;
for (int i = 0; i bit = (bs[i] & 0x0f0) >> 4;
sb.append(chars[bit]);
bit = bs[i] & 0x0f;
sb.append(chars[bit]);
}
return sb.toString();
}
//byteTo16HexStr//161020
public static String bytesToHexString(byte[] bArray) {
StringBuffer sb = new StringBuffer(bArray.length);
String sTemp;
for (int i = 0; i sTemp = Integer.toHexString(0xFF & bArray[i]);
if (sTemp.length() <2)
sb.append(0);
sb.append(sTemp.toUpperCase());
}
return sb.toString();
}
//读取系统属性
String getproduct &#61; getSystemProperty("ro.epay.serial","1");
/**
* 读取属性
* */
public String getSystemProperty(String key, String def) {
String result &#61; null;
try {
Class spCls &#61; Class.forName("android.os.SystemProperties");
Class[] typeArgs &#61; new Class[2];
typeArgs[0] &#61; String.class;
typeArgs[1] &#61; String.class;
Constructor spcs &#61; spCls.getConstructor(null);
Object[] valueArgs &#61; new Object[2];
valueArgs[0] &#61; key;
valueArgs[1] &#61; def;
Object sp &#61; spcs.newInstance(null);
Method method &#61; spCls.getMethod("get", typeArgs);
result &#61; (String) method.invoke(sp, valueArgs);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return result;
}