FileStream 的用法

    xiaoxiao2021-12-14  16

    package 练习12号; import java.io.*; public class FileStream { public static void main(String[] args) throws IOException{ readFile2(); } public static void writeFile() throws IOException{ FileOutputStream fw=new FileOutputStream("zxn.txt"); fw.write("abcdefg".getBytes()); } public static void readFile() throws IOException{ FileInputStream fr=new FileInputStream("zxn.txt"); int ch; while((ch=fr.read())!=-1){ System.out.println((char)ch); } } public static void readFile2() throws IOException{ FileInputStream fr2=new FileInputStream("zxn.txt"); int len=0; byte[] buf=new byte[1024]; while((len=fr2.read(buf))!=-1){ System.out.println(new String(buf,0,len)); } fr2.close(); } }

    输出结果:

    abcdefg

    转载请注明原文地址: https://ju.6miu.com/read-971406.html

    最新回复(0)