1. java中的File类
     文件的路径设置不够灵活--路径前不加/代表项目根目录
     加/代表分区根目录(Windows)

    public static void readTxtFile(String filePath){
         try {
                 String encoding="GBK";
                 File file=new File(filePath);
                 String absolutePath = file.getAbsolutePath();//显示路径
                 if(file.isFile() && file.exists()){ //判断文件是否存在
                     InputStreamReader read = new InputStreamReader(
                     new FileInputStream(file),encoding);//考虑到编码格式
                     BufferedReader bufferedReader = new BufferedReader(read);
                     String lineTxt = null;
                     while((lineTxt = bufferedReader.readLine()) != null){
                         System.out.println(lineTxt);
                     }
                     read.close();
         }else{
             System.out.println("找不到指定的文件");
         }
         } catch (Exception e) {
             System.out.println("读取文件内容出错");
             e.printStackTrace();
         }  
    }
    public static void main(String[] args) {
         String path = "src\\cn\\shafish\\filetest\\a.txt";
               //String path = "/a.txt"
         readTxtFile(path);
     }
  2. Class.getResourceAsStream()--通过传入的文件名去加载对应文件
     同样加/与不加/的区别

    getClass().getResourceAsStream("/af-restful.xml")
    //类.class.getResourceAsStream("/af-restful.xml")
    InputStream stream = getClass().getResourceAsStream("/af-restful.xml");//代表项目根目录(src下与包名同级)下的af-restful.xml文件
    InputStream stream = getClass().getResourceAsStream("af-restful.xml");//代表当前类同级路径下的af-restful.xml文件
    File file = new File(getClass().getResourceAsStream("/af-restful.xml").getFile());