ByteArrayInputStream(byte[] buf); ByteArrayInputStream(byte[] buf,int offset,int length );
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class TestByteArrayInputStream {
public static void main(String[] args) throws IOException {
// 初始化字节数组
byte[] buf = new byte[3];
buf[0] = 100;
buf[1] = 101;
buf[2] = 102;
// 创建输入流
ByteArrayInputStream input = new ByteArrayInputStream(buf);
// 从输入流中读取数据
byte[] out = new byte[3];
input.read(out);
System.out.println(new String(out));
// 关闭输入流
input.close();
}
}
FileInputStream(File file);//通过系统中的File对象file指定 FileInputStream(String name);//通过系统中路径名name指定同样的我们使用重写的InputStream中的方法的名称来实现读文件内容。
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class TestFileInputStream {
public static void main(String[] args) throws FileNotFoundException {
try {
// 创建输入流
FileInputStream input = new FileInputStream("D:/demo/test.txt");
// 从输入流中读取数据
while (input.available() > 0) {
int out = input.read();
System.out.println((char) out);
}
// 关闭输入流
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.Date;
public class TestObjectInputStream {
public static void main(String[] args) throws ClassNotFoundException {
try {
// 创建文件输入流
FileInputStream file = new FileInputStream("D:/demo?test.tmp");
// 创建对象输入流
ObjectInputStream object = new ObjectInputStream(file);
// 读取对象的数据
int i = object.readInt();
String string = (String) object.readObject();
Date date = (Date) object.readObject();
System.out.println("i=" + i);
System.out.println("string=" + string);
System.out.println("date=" + date);
// 关闭流
object.close();
file.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
StringBufferInputStream(String s); //以从指定字符串读取数据
import java.io.IOException;
import java.io.StringBufferInputStream;
public class TestStringBufferInputStream {
public static void main(String[] args) {
// 创建输入流
StringBufferInputStream input = new StringBufferInputStream("Hello World!");
// 从输入流中读取数据
while (input.available() > 0) {
int out = input.read();
System.out.print((char) out);
}
// 关闭输入流
try {
input.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class TestBufferedInputStream {
private void mian() {
// TODO Auto-generated method stub
try {
// 创建文件输入流
FileInputStream input = new FileInputStream("D:/demo/test.txt");
BufferedInputStream buffer = new BufferedInputStream(input);
// 从输入流中读取数据
while (buffer.available() > 0) {
int out = buffer.read();
System.out.print((char) out);
}
// 关闭流
buffer.close();
input.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有