How do I convert an InputStream to a string in Java?

Learn how to load text in a binary file to an InputStream and convert it to a string using ByteArrayOutputStream with a ByteBuffer.

By Brian L. Gorman
September 16, 2016
Screenshot from "How to convert an InputStream to a string" Screenshot from "How to convert an InputStream to a string"

When reading text from a binary file or serialized transmission in Java, developers will often need to convert the stream to text. In this video, Brian Gorman begins with a quick overview of working with binary data using input and output streams. He then teaches you how to open a file into an InputStream and use ByteArrayOutputStream with a ByteBuffer to output the stream as a string. Novice Java developers will also learn how to use the StringBuilder object to build a string from their incoming data.

Access in-depth Java training with our Beginning Java Learning Path

Learn faster. Dig deeper. See farther.

Join the O'Reilly online learning platform. Get a free trial today and find answers on the fly, or master something new and useful.

Learn more

Brian L. Gorman is an experienced .NET developer, certified as an MCSD in C# .NET. Holding a Masters of Science in computer information systems, he has many years of experience instructing college-level SQL database, C#, VB.NET, Java, and Microsoft Office courses. Brian has also authored a number of full technical video courses on these subjects.

Post topics: Software Engineering
Post tags: Questions