-
/*Java InputStream to String ExampleThis Java InputStream to String example shows how to convert InputStream to String in Java.*/public class ConvertInputStreamToStringExample
{
public static void main(String args[]) throws IOException{
//get InputStream of a fileInputStream is = new FileInputStream(“c:/data.txt”);String strContent;
/** There are several way to convert InputStream to String. First is using* BufferedReader as given below.*/
//Create BufferedReader objectBufferedReader bReader = new BufferedReader(new InputStreamReader(is));StringBuffer sbfFileContents = new StringBuffer();String line = null;
//read file line by linewhile( (line = bReader.readLine()) != null)
{sbfFileContents.append(line);}
//finally convert StringBuffer object to String!strContent = sbfFileContents.toString();
/** Second and one liner approach is to use Scanner class. This is only supported* in Java 1.5 and higher version.*/
strContent = new Scanner(is).useDelimiter(“\\A”).next();}}
Friday, 13 April 2018
Popular Posts
-
Build interactive, data-driven websites with the potent combination of open-source technologies and web standards, even if you have only ...
-
Java :- It is a fast, secure and reliable general purpose computer programming language. Python :- A Readable, efficient and powerfu...
-
Business Analytics Definition "Study of business data using statistical technique and programming for creating decision suppo...
-
Variables in R A variables are nothing but reserved memory locations to store values. This means that when you create a variab...
-
What is Python? → Python is an interpreted High level programming Language for General purpose programming. Python is created by Gui...
-
Why do we need Analytics ? → Data analytics helps organizations harness their data and use it to identify few opportunities. - Cost re...
-
- > is the prompt sign in R - The assignment operators are the left arrow with dash <- and equal sign =. > x <- 20 ...
-
Java is develop by James Gosling in 1991 Java is a developed in the early 90s in Sun Microsystems company. Java first version release in ...
-
Importing Data Files Spreadsheet (Excel) file data The xlsx package has the function read.xlsx ( ) for reading Excel files. This ...
-
1. Simple & Easy To Learn Open Source High-level Interpreted Large community 2. Portable & Extensible 3. Web ...

0 Comments:
Post a Comment