0

So i need to read a text file and convert it to String in order for me to start using shift chipper to chipper my msg. all i found of how to read text file involves a loop, and it in itself only show printed character from the first to the next until there's no more text.

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(); 

is there a way so i can just

File fl = new File("d:/chipper/msg/msg.txt");
textToChipper = fl;
chipper();
Arivas
  • 5
  • 5
  • https://stackoverflow.com/questions/4716503/reading-a-plain-text-file-in-java might help – seenukarthi Oct 15 '19 at 17:09
  • Possible duplicate of [Reading a plain text file in Java](https://stackoverflow.com/questions/4716503/reading-a-plain-text-file-in-java) – Anil Oct 15 '19 at 17:19

1 Answers1

1

You could do something like this:

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