文件结构
package Test; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Array; import java.util.Arrays; import java.util.EnumMap; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import com.sun.istack.internal.Nullable; public class Test { public static void main(String[] args) throws IOException {
// 最好别用FileReader,容易漏读 // 如果是window系统,/需要换成/ FileInputStream in = new FileInputStream("/Users/mac/eclipse-workspace/Demo/src/Test/file.txt"); byte[] buffer = new byte[1024]; int len = 0; while((len=in.read(buffer))!=-1) { System.out.println(new String(buffer,0,len)); } in.close(); // 一定记得关闭! } }
结果
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/281171.html