Read line from an InputStream [duplicate]

You should use BufferedReader with FileInputStreamReader if your read from a file BufferedReader reader = new BufferedReader(new FileInputStreamReader(pathToFile)); or with InputStreamReader if you read from any other InputStream BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); Then use its readLine() method in a loop while(reader.ready()) { String line = reader.readLine(); } But if you really love InputStream …

Read more

Java – Read line using InputStream [duplicate]

You should use BufferedReader with FileInputStreamReader if your read from a file BufferedReader reader = new BufferedReader(new FileInputStreamReader(pathToFile)); or with InputStreamReader if you read from any other InputStream BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); Then use its readLine() method in a loop while(reader.ready()) { String line = reader.readLine(); } But if you really love InputStream …

Read more

Create a Zip File in Memory

Use ByteArrayOutputStream with ZipOutputStream to accomplish the task. you can use ZipEntry to specify the files to be included into the zip file. Here is an example of using the above classes, String s = “hello world”; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try(ZipOutputStream zos = new ZipOutputStream(baos)) { /* File is not on the disk, …

Read more