chap8-3.txt

来自「JAVA 学习资源」· 文本 代码 · 共 34 行

TXT
34
字号
// 程序8-3
import java.io.*;
class fileWriteInfo {
    void writeInfo( )throws IOException{
        int size=0;
        byte b[ ]=new byte[6]; 			// 创建一个文件输出对象
        FileOutputStream fout=new FileOutputStream("d:/abc.txt");

        try{
            System.out.print("Enter 6 chars: ");
            for(int i=0;i<6;i++) 			// 从键盘读6个字节
                b[i]=(byte)System.in.read( );
            
            fout.write(b); 			// 将数组的内容一次写到文件
        }catch(IOException e){
            System.out.print("file IOException!");
        }finally{
            fout.close( ); 			// 关闭文件
        }
    }
}
    
public class fileWriteTest {
    public static void main(String args[ ])  {
        fileWriteInfo obj=new fileWriteInfo ( ); 
        try{
            obj.writeInfo( );
        }catch(IOException e) {
            System.out.println("File not found : "+e);
            e.printStackTrace( );
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?