编程语言
首页 > 编程语言> > java-读取文件

java-读取文件

作者:互联网

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class Readjdbc {
    /**
     *day94打卡
     * 读取jdbc配置文件
     * @param args
     */
    public static void main(String[] args) throws IOException {
        File folder = new File("D:\\workspace_IDEA\\Exceltest\\src\\main\\resources\\jdbc.properties");
        String encoding = "utf-8";
        //存储读取内容
        HashMap<String,String> map = new HashMap<>();
        //读取文件
        if(folder.isFile() && folder.exists()){
            InputStreamReader read = new InputStreamReader(new FileInputStream(folder),encoding);
            BufferedReader bufferedReader = new BufferedReader(read);
            String line = null;
            while((line = bufferedReader.readLine())!= null){
                System.out.println(line);
                String[] s = line.split("=");
                map.put(s[0],s[1]);
            }
            bufferedReader.close();
            read.close();
            //输出map
            for (Map.Entry<String,String> entry:map.entrySet() ) {
                System.out.println(entry.getKey() + "->" + entry.getValue());
            }
        }
        else{
            System.out.println("找不到文件!");
        }


    }
}

 

标签:文件,java,String,map,new,line,folder,读取
来源: https://www.cnblogs.com/yixiaobaitest/p/16182416.html