You understand this code except for this

String temp = new String (buffer1); 

What does an object of type string with an array named buffer1

 public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader (new InputStreamReader (System.in)); String file1 = reader.readLine (); String file2 = reader.readLine (); reader.close (); FileInputStream fileInputStream = new FileInputStream (file1); FileOutputStream fileOutputStream = new FileOutputStream (file2); ArrayList<String> list = new ArrayList<String> (); byte[] buffer1 = new byte[fileInputStream.available ()]; while (fileInputStream.available () > 0) { fileInputStream.read (buffer1); } String temp = new String (buffer1); for (String z : temp.split(" ")) { float x = Float.parseFloat(z); list.add(Math.round(x) + " "); } for (String h : list) { fileOutputStream.write(h.getBytes()); } fileInputStream.close (); fileOutputStream.close (); } } 

    1 answer 1

    This is a call to a string constructor with arguments.

     byte[] buffer1 = ... String temp = new String (buffer1); 

    This creates an instance of the String class from an array of bytes that you read from the file.

    • I just can’t understand why it was necessary to shove an array into an object string - isn't it possible to just read through the array and perform this action - Vasya Papkin Son
    • for (String s: temp.split ("")) {Float f = Float.parseFloat (s); list.add (Math.round (f) + ""); } - Vasya Papkin Son
    • one
      @ VasyaPapkinSyn for the sake of the split ("") method, which breaks a string into substrings by spaces - Stranger in the Q