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);
    }
  • 相关阅读:
    react引用antd的form表单
    前端学习之--谷歌浏览器使用
    react引用ant的table组件
    git 提交解决冲突
    git将本地仓库推送到远程仓库
    操作DOM
    javaScript基础篇之数据类型
    css之水平居中设置
    css之颜色值、单位
    CSS属性简写
  • 原文地址:https://www.cnblogs.com/chenchaochao/p/5527292.html
Copyright © 2011-2022 走看看