Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

ByteArrayOutputStream

import java.io.ByteArrayOutputStream;

class Main {
  public static void main(String[] args) {

    String data = "This is a line of text inside the string.";

    try {
      // Creates an output stream
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      byte[] array = data.getBytes();

      // Writes data to the output stream
      out.write(array);

      // Retrieves data from the output stream in string format
      String streamData = out.toString();
      System.out.println("Output stream: " + streamData);

      out.close();
    }

    catch(Exception e) {
      e.getStackTrace();
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java string get ith char 
Java :: uses or overrides a deprecated API. 
Java :: spring boot onetomany relationsion 
Java :: integer palindrome in java 
Java :: remove last character from stringbuffer 
Java :: binary to octal conversion java program 
Java :: java get current index in for loop 
Java :: sublist java 
Java :: java mcq 
Java :: declare bufferedreader java 
Java :: Java printf() Method 
Java :: convert java to python 
Java :: jdk path 
Java :: java map create with values 
Java :: what is whitespace in java 
Java :: how to add a listener to a toggle group radio buttons javafx 
Java :: Divide two integers without using multiplication, division and mod operator 
Java :: line break in android xml dynamically 
Java :: Employee Java. 
Java :: convert date to localdate java 
Java :: java multithreading 
Java :: prime numbers program in java 
Java :: java parse json to class 
Java :: setter getter array java 
Java :: maximum arrays size in java 
Java :: android foreground services set auto cancel not working 
Java :: practical1_answer 
Java :: java easy list 
Java :: finding length of arrays in java 
Java :: how to create a console in java gui 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =