Java Files create InputStream

Description

Java Files create InputStream

import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class Main {

   public static void main(String[] args) {
      Path file = Paths.get("Main.java");
      Path newFile = Paths.get("MainUsers.txt");
      try (InputStream in = Files.newInputStream(file);
            OutputStream out = Files.newOutputStream(newFile, StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
         int data = in.read();
         while (data != -1) {
            out.write(data);/*  w ww.j  a  v a  2  s.com*/
            data = in.read();
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}



PreviousNext

Related