将文件复制到输出流
import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files;//from n o w j a v a . c o m import java.nio.file.Path; public class Main { public static void main(String[] args) { Path sourceFile = FileSystems.getDefault().getPath( "C:/home/docs/users.txt"); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { Files.copy(sourceFile, outputStream); byte arr[] = outputStream.toByteArray(); System.out.println("The contents of " + sourceFile.getFileName()); /* 来自 *n o w j a v a . c o m*/ for (byte data : arr) {