1、以"字节"为单位从文件中读取数据
采用的具体的类与方法有:
InputStram类-----> read() 方法 //一次读取一个字节
-----> read(byte[] b) //一次读取多个字符
注意:这里 从文件中读取的数据 是按照 字节类型 来读的,所以转换数据类型的时候,注意用print()方法打印输出要强制 char 类型转换。
附代码:
File file = new File(newfileName);
InputStream in = null;
try {
in = new FileInputStream(file); //一次读一个字节
int zj; //定义读取的字节
while((zj=in.read()) != -1){
System.out.write(zj);
//System.out.print((char)tempbyte);
}
//按多个字节读
// byte b = new byte[1024];
// while((zj=in.read(b)) != -1){
// System.out.write(zj);
// //System.out.print((char)tempbyte);
// }
in.close();
} catch (IOException e) {
e.printStackTrace();
}
技术难点: read()方法:从