zoukankan      html  css  js  c++  java
  • Java编码字符串,解码字符串,取得文件大小,读文件内容

    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);
    }
  • 相关阅读:
    python-Python调用wcf接口
    一个数据驱动的ui自动化框架思路
    selenium分布式部署
    UI自动化-Element is not clickable at point-----问题记录
    idea下载git代码
    windows的hosts文件路径
    端口号
    Hadoop压缩
    MongoDB(单节点)环境配置
    快排
  • 原文地址:https://www.cnblogs.com/chenchaochao/p/5527292.html
Copyright © 2011-2022 走看看