-
/*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
-
This textbook grew out of notes for the ECE143 Programming for Data Analysis class that the author has been teaching at University of Cali...
-
What you'll learn Use SQL commands to filter, sort, & summarize data; manipulate strings, dates, & numerical data from differe...
-
There are 6 modules in this course Cybersecurity affects everyone, including in the delivery of basic products and services. If you or you...
-
This Python code defines a function and then calls it with specific arguments. Let's break it down step by step: Function Definition: ...
-
In Python, dictionaries are compared based on their keys and corresponding values. When you use the != operator to compare two dictionarie...
-
What you'll learn Develop custom Python scripts to automate cybersecurity tasks. Apply Python to meet objectives through the cybersecu...
-
import turtle def draw_ring(color, x, y): turtle.penup() turtle.color(color) turtle.goto(x, y) turtle.pendown() turtle...
-
There are 12 modules in this course Stanford's "Introduction to Statistics" teaches you statistical thinking concepts that a...
-
What you'll learn Create basic visualizations such as line graphs, bar graphs, and pie charts using Excel spreadsheets. Explain the im...
-
Are you eager to dive into the world of Java programming and software engineering? Coursera offers an excellent course titled Java Program...
Categories
AI
(28)
Android
(24)
AngularJS
(1)
Assembly Language
(2)
aws
(17)
Azure
(7)
BI
(10)
book
(4)
Books
(121)
C
(77)
C#
(12)
C++
(82)
Course
(66)
Coursera
(184)
Cybersecurity
(24)
data management
(11)
Data Science
(99)
Data Strucures
(7)
Deep Learning
(11)
Django
(6)
Downloads
(3)
edx
(2)
Engineering
(14)
Excel
(13)
Factorial
(1)
Finance
(6)
flutter
(1)
FPL
(17)
Google
(19)
Hadoop
(3)
HTML&CSS
(46)
IBM
(25)
IoT
(1)
IS
(25)
Java
(93)
Leet Code
(4)
Machine Learning
(46)
Meta
(18)
MICHIGAN
(5)
microsoft
(4)
Pandas
(3)
PHP
(20)
Projects
(29)
Python
(792)
Python Coding Challenge
(273)
Questions
(2)
R
(70)
React
(6)
Scripting
(1)
security
(3)
Selenium Webdriver
(2)
Software
(17)
SQL
(41)
UX Research
(1)
web application
(8)
0 Comments:
Post a Comment