从文件读取字节
//package com.nowjava;/* 来自 nowjava.com*/ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Main { public static void main(String[] argv) throws Exception { File grammarFile = new File("Main.java"); System.out.println(java.util.Arrays .toString(readBytesFromFile(grammarFile))); } /** 时 代 J a v a 公 众 号 - N o w J a v a . c o m 提供 **/ /** * @param grammarFile * @return * @throws FileNotFoundException * @throws IOException */ public static byte[] readBytesFromFile(File grammarFile) throws FileNotFoundException, IOException { byte[] oldBytes = null; if (grammarFile.exists()) { FileReader reader = new FileReader(grammarFile); ByteArrayOutputStream oldBytesStream = new ByteArrayOutputStream();