How to convert string into InputStream in java

This example shows you how to convert String object into InputStream object in java. You can convert String to InputStream using ByteArrayInputStream class. This class constructor takes the string byte array which can be done by calling the getBytes() method. Below is the example code: package com.java.connect.io; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.UnsupportedEncodingException; //How to […]

Continue reading


Read text file in java

This example shows you how to read a text file in java. To read the text file you need to get BufferReader object by passing FileReader, than you can read a line by line file content and append each line into StringBuffer object. Below is the example of code: package com.java.connect.io; import java.io.BufferedReader; import java.io.File; […]

Continue reading


Read file into byte array example

This example shows you to read the file into byte array in java. Below is the example code: package com.java.connect.io; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; //Read file into byte array example public class ReadFileIntoByteArrayExample { public static void main(String[] args) throws IOException { // Get the file object File file = new […]

Continue reading


Properties to XML in java

This example shows you how to store Properties object’s key and value in XML file Below is the example code: package com.java.connect.io; import java.io.FileOutputStream; import java.util.Properties; //Properties to XML in java public class PropertiesToXmlExample { public static void main(String[] args) throws Exception { Properties properties = new Properties(); properties.setProperty("person.name", "Mahendra SUDA"); properties.setProperty("person.age", "29 years"); properties.setProperty("person.occupation", […]

Continue reading


Xml to properties example

This example shows you how to get the key and value in the Java Properties object. We will read the below xml file content into java Properties object. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <entry key="person.name">Mahendra SUDA</entry> <entry key="person.age">29 years</entry> <entry key="person.occupation">Software</entry> </properties> Below is the example code of java: package com.java.connect.io; import […]

Continue reading


How to use LineNumberReader to read file in java

This example show you the use of LineNumberReader class of java IO API, This class used to read the file line by line. Below is the example of using LineNumberReader to read the file content. package com.java.connect.io; import java.io.File; import java.io.FileReader; import java.io.LineNumberReader; //How to use LineNumberReader to read file in java public class LineNumberReaderExample […]

Continue reading