1.Java编码字符串
public static String encode(String s, String encodeType) { if (s == null || s.equals("")) { return ""; } if (encodeType == null || encodeType.equals("")) { return s; } try { return URLEncoder.encode(s, encodeType); } catch (Exception e) { } return s; }
2.Java解码字符串
public static String decode(String s, String encodeType) { if (s == null || s.equals("")) { return ""; } if (encodeType == null || encodeType.equals("")) { return s; } try { s = URLDecoder.decode(s, encodeType); } catch (Exception e) { } return s; }
3.Java取得文件大小
public static long getFileSize(File f) throws Exception { long s = 0; if (f.isDirectory()) { for (File file : f.listFiles()) { s += getFileSize(file); } } else { FileInputStream fis = null; try { fis = new FileInputStream(f); s = fis.available(); } catch (IOException e) { } finally { if (fis != null) { fis.close(); } } } return s; }
4.Java读文件内容
public static String readFile(String path, String encoding) { File file = new File(path); return readFile(file, encoding); }