📜  如何在java代码示例中读取文本文件作为变量

📅  最后修改于: 2022-03-11 14:52:11.088000             🧑  作者: Mango

代码示例1
public static void readAsString() {
             String lCurentDir = System.getProperty("user.dir")+"/aa.txt";
             FileReader fr;
            try {
                fr = new FileReader(lCurentDir);
                 BufferedReader br = new BufferedReader(fr);
                    String s="";
                    s=br.readLine();
                    System.out.println(s);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
               

        }