获取项目中.txt 文件的内容

package com.fh.controller.ruitai.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

public class TomcatUtil {
    /**
     * @Description  读取文件
     * @author 张洋.
     * @date
     * @return
     * @throws ExceptionFile
     */
    public static String GetIdentified() throws Exception { // 
        File f = new File(TomcatUtil.class.getClassLoader().getResource("tomcatdentified.txt").getPath().replaceAll("%20", " "));
        FileInputStream input = new FileInputStream(f);
        BufferedInputStream buf = new BufferedInputStream(input);
        byte[] b = new byte[(int) f.length()];
        input.read(b);
        input.close();
        String identified=new String(b);
        return identified;
    }
        public static void main(String[] args) {
            try {
                GetIdentified();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
}
作者:逆舟
https://www.cnblogs.com/zy-jiayou/
本博客文章均为作者原创,转载请注明作者和原文链接。
原文地址:https://www.cnblogs.com/zy-jiayou/p/6457866.html