Java中的FileOutputStream与FileInputStream

来源:互联网 发布:g76螺纹编程第一刀 编辑:程序博客网 时间:2024/05/19 22:59
package Number;//import java.util.*;import java.io.File;//如果不导入这个类 则提示错误File cannot be resolved to a typeimport java.io.FileOutputStream;import java.io.FileInputStream;public class Test{public static void main(String[] args){File file = new File("word.txt");try{FileOutputStream out = new FileOutputStream(file);String temp = "lallalaalalala";byte buy[] = temp.getBytes();//字节数组System.out.println(temp.getBytes());out.write(buy);//通过字节数组来写入out.close();}catch(Exception e){e.printStackTrace();}try{FileInputStream in = new FileInputStream(file);byte byt[] = new byte[1024];//初始化字节数组1024个0int len  = in.read(byt);//从文件中读取信息:长度System.out.println(new String(byt,0,len) );//String(byt,0,len)输出byt字节数组中的类容,输出范围0-lengthin.close();}catch(Exception e){e.printStackTrace();}}}
输出结果:
[B@3b896429lallalaalalala
                                             
0 0
原创粉丝点击