Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: JM Brun
Added: Jun 6, 2018 9:01 AM
Modified: Jun 7, 2018 7:42 AM
Views: 8
File to InputStream to String
  1. http://www.baeldung.com/convert-file-to-input-stream
  2.  DataSet dataSet = from(this.getClass().getResourceAsStream("dataset-sample_cache.json"));
  3.  
  4. http://www.baeldung.com/convert-input-stream-to-a-file
  5.  
  6.         File targetFile = new File("src/main/resources/targetFile.tmp");
  7.         OutputStream outStream = new FileOutputStream(targetFile);
  8.  
  9.         byte[] buffer = new byte[8 * 1024];
  10.         int bytesRead;
  11.         while ((bytesRead = jsonResult.read(buffer)) != -1) {
  12.             outStream.write(buffer, 0, bytesRead);
  13.         }
  14.         IOUtils.closeQuietly(jsonResult);
  15.         IOUtils.closeQuietly(outStream);