public class fileutils ;
/*** 判斷目錄是否存在,不存在則判斷是否建立成功
** @param dirpath 目錄路徑
* @return : 存在或建立成功
: 不存在或建立失敗
*/public static boolean createorexistsdir(string dirpath) else
}/**
* 判斷檔案是否存在,不存在則判斷是否建立成功
** @param file 檔案
* @return : 存在或建立成功
: 不存在或建立失敗
*/public static boolean createorexistsfile(file file)
// 如果存在,是檔案則返回true,是目錄則返回false
if (file.exists())
if (!createorexistsdir(file.getparentfile().getabsolutepath()))
try catch (ioexception e)
}/**
* 用於判斷指定字元是否為空白字元,空白符包含:空格、tab鍵、換行符。
** @param s
* @return
*/private static boolean isspace(string s)
for (int i = 0, len = s.length(); i < len; ++i)
}return true;
}public static boolean copyfile(file srcfile, file destfile)
public static boolean movefile(file srcfile, file destfile)
/*** 獲取檔案的md5校驗碼
** @param filepath 檔案路徑
* @return 檔案的md5校驗碼
*/public static string getfilemd5tostring(string filepath)
/*** 獲取檔案的md5校驗碼
** @param file 檔案
* @return 檔案的md5校驗碼
*/public static string getfilemd5tostring(file file)
/*** 獲取檔案的md5校驗碼
** @param file 檔案
* @return 檔案的md5校驗碼
*/public static byte getfilemd5(file file)
digestinputstream dis = null;
try
}md = dis.getmessagedigest();
return md.digest();
} catch (nosuchalgorithmexception | ioexception e) finally
return null;
}public static string ge***5byfile(file file)
while ((length = fis.read(buffer)) != -1)
byte bytes = md.digest();
if (bytes == null)
for (int i = 0; i < bytes.length; i++)
if (md5s.length() == 1)
}// trace.d(logtag, "getfilemd5, genmd5 success! spend the time: "+ (system.currenttimemillis() - s) + "ms");
string value = buf.tostring();
int fix_num = 32 - value.length();
for (int i = 0; i < fix_num; i++)
return value;
} catch (exception ex) finally
} catch (ioexception ex) }}
/*** bytearr轉hexstring
* 例如:
* bytes2hexstring(new byte ) returns 00a8
** @param bytes 位元組陣列
* @return 16進製制大寫字串
*/private static string bytes2hexstring(byte bytes)
int len = bytes.length;
if (len <= 0)
char ret = new char[len << 1];
for (int i = 0, j = 0; i < len; i++)
return new string(ret);
}/**
* 複製或移動檔案
** @param srcfile 原始檔
* @param destfile 目標檔案
* @param ismove 是否移動
* @return : 複製或移動成功
: 複製或移動失敗
*/private static boolean copyormovefile(file srcfile, file destfile, boolean ismove)
// 原始檔不存在或者不是檔案則返回false
if (!srcfile.exists() || !srcfile.isfile())
// 目標檔案存在且是檔案則返回false
if (destfile.exists() && destfile.isfile())
// 目標目錄不存在返回false
if (!createorexistsdir(destfile.getparentfile().getabsolutepath()))
try catch (filenotfoundexception e)
}/**
* 將輸入流寫入檔案
** @param file 檔案
* @param is 輸入流
* @return : 寫入成功
: 寫入失敗
*/if (file == null || is == null)
if (!createorexistsfile(file))
outputstream os = null;
try
return true;
} catch (ioexception e) finally
}public static void closeio(closeable... closeables)
for (closeable closeable : closeables) catch (ioexception e) }}
}/**
* 刪除檔案
** @param file 檔案
* @return : 刪除成功
: 刪除失敗
*/public static boolean deletefile(file file)
public static boolean deletedirectory(string spath)
file dirfile = new file(spath);
//如果dir對應的檔案不存在,或者不是乙個目錄,則退出
if (!dirfile.exists() || !dirfile.isdirectory())
boolean flag = true;
//刪除資料夾下的所有檔案(包括子目錄)
file files = dirfile.listfiles();
for (int i = 0; i < files.length; i++) //刪除子目錄
else
}if (!flag) return false;
//刪除當前目錄
if (dirfile.delete()) else
}/**
* 返回byte的資料大小對應的文字
** @param size
* @return
*/public static string getdatasize(long size)
decimalformat formater = new decimalformat("####.00");
if (size < 1024) else if (size < 1024 * 1024) else if (size < 1024 * 1024 * 1024) else if (size < 1024 * 1024 * 1024 * 1024) else
}/**
* 保留檔名及字尾
*/public static string getfilenamewithsuffix(string pathandname) else
}}
關於Android開發中使用的XML
1.布局 framelayout 以堆疊方式顯示乙個或多個子檢視。gridlayout 將子檢視按行和列排列。linearlayout 將所有子檢視排列成一行或一列。relativelayout 一種靈活的布局,以相對於其他檢視的方式排列檢視。2.常見的介面元素 button 按鈕控制項 check...
Android應用開發中使用Cookie
cookie是網景公司發明的,為了 的伺服器端辨別使用者的身份,保持session會話而儲存到使用者本地磁碟上的使用者資料,該資料是經過加密的。cookie是由伺服器端生成,傳送給客戶端的 user agent一般是瀏覽器 客戶端瀏覽器會將cookie的key value儲存到某個目錄下的文字檔案內...
Android 開發中使用 SQLite 資料庫
sqlite 介紹 sqlite 乙個非常流行的嵌入式資料庫,它支援 sql 語言,並且只利用很少的記憶體就有很好的效能。此外它還是開源的,任何人都可以使用它。許多開源專案 mozilla,php,python 都使用了 sqlite.sqlite 由以下幾個元件組成 sql 編譯器 核心 後端以及...