📄 chap8-3.txt
字号:
// 程序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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -