-2

Im finding a lot of complicated answers however, I know there is a simple way and Im just not fitting it together.

I want the txt file to be put into the String txtString. inFS is for later parsing. What do I need to put the txt file to the string txtString?

My code:

fileByteStream = new FileInputStream("mytextfile.txt");
inFS = new Scanner(fileByteStream);         
txtString = ??
3
  • What ways are you finding? while loops that ensure the file has a next line? Commented Feb 7, 2017 at 14:14
  • If you have the latest version of Java: String content = new String(Files.readAllBytes(Paths.get("readMe.txt"))); Commented Feb 7, 2017 at 14:16
  • Nope, it needs to be simple. What do i put where the ?? are in my post. Commented Feb 7, 2017 at 14:21

1 Answer 1

3
    String content = new String(Files.readAllBytes(Paths.get("mytextfile.txt")));

works with java7

Sign up to request clarification or add additional context in comments.

1 Comment

You should always specify the encoding when using new String(byte[] b).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.