|
方法名称 |
描述 |
| public void close() throws IOException | 关闭输出流 |
| public void flush() throws IOException | 刷新缓冲区 |
| public void write(byte[] b) throws IOException | 将一个byte数组写入数据流 |
| public void write(byte[] b,int off,int len) throws IOException | 将一个指定范围的byte数组写入数据流 |
| public abstract void write(int b) throws IOException | 将一个字节数据写入数据流 |
public static void main(String[] args) throws Exception {
// 创建一个以当前工程目录下的名为“helloworld.txt”的文本文件
File file = new File("hellowolrd.txt");
OutputStream outputStream = null;
// 通过FileOutPutStream的子类实例化OutputStream对象
outputStream = new FileOutputStream(file);
// 声明一个字符串
String str = "hello,world";
// 将字符串转换成字节数组
byte[] b = str.getBytes();
// 写入数据
outputStream.write(b);
// 关闭输出流
outputStream.close();
outputStream.flush();
}
|
方法名称 |
描述 |
| public void avaliable() throws IOException | 可以取得输入文件的大小 |
| public void close() throws IOException | 关闭输入流 |
| public abstract int read() throws IOException | 读取内容,以数字的方式读取 |
| public int read (byte b) throws IOException | 将内容读到byte数组,同时返回读入的个数 |
public static void main(String[] args) throws Exception {
// 创建一个以当前工程目录下的名为“helloworld.txt”的文本文件
// 这个文件在上一个例子里已经创建,并且里面已有数据
File file = new File("hellowolrd.txt");
// 声明InputStream对象
InputStream inputStream = null;
// 通过FileInputStream子类实例化InputStream对象
inputStream = new FileInputStream(file);
// 声明一个字节数组用以接收读入的数据
byte[] b = new byte[1024];
// 开始读入数据,将数据内容读到此数组中
inputStream.read(b);
// 关闭输入流
inputStream.close();
// 在控制台打印
System.out.println(new String(b));
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有