提取文件中的值并将其转换为字符串以获得更多通用性

Extracting the value in the a file and convert it to string for more versatility

所以我需要读取一个文本文件并将其转换为字符串,以便我开始使用 shift chipper 来切碎我的消息。 我发现的关于如何读取文本文件的所有内容都涉及一个循环,它本身只显示从第一个到下一个的打印字符,直到没有更多文本为止。

File fl = new File("d:/chipper/msg/msg.txt");
BufferedReader brText = new BufferedReader(new FileReader(fl));
String text = null;
while((text=brText.readLine())!=null){
System.out.println(text);
}
brPesan.close(); 

有没有办法让我可以

File fl = new File("d:/chipper/msg/msg.txt");
textToChipper = fl;
chipper();

你可以这样做:

textToChipper = new String(Files.readAllBytes(Paths.get("d:/chipper/msg/msg.txt")));