Java: accessing a List of Strings as an InputStream

前端 未结 7 1555
情深已故
情深已故 2021-02-05 11:24

Is there any way InputStream wrapping a list of UTF-8 String? I\'d like to do something like:

InputStream in = new XyzInputStream( List         


        
7条回答
  •  离开以前
    2021-02-05 11:57

    In my case I had to convert a list of string in the equivalent file (with a line feed for each line).

    This was my solution:

    List inputList = Arrays.asList("line1", "line2", "line3");
    
    byte[] bytes = inputList.stream().collect(Collectors.joining("\n", "", "\n")).getBytes();
    
    InputStream inputStream = new ByteArrayInputStream(bytes);
    

提交回复
热议问题