0%

文件流的使用(上传图片例子)

1.文件流的使用
1.1读取文件,转化成流
获取当前路径,创建file,把file写进流里,建立byte数组,直接写进流里

1
2
3
4
5
6
file file =new File(String path);
if(!file.exist()){
return;
}
inputSteam input=new inputstream(file);
int datLength=fis.available(); //文件的长度

获取文件的长度
直接写进byte数组

1
2
3
4
byte[] ecgByte = new byte[datLength];
while(readLength=fis.read(ecgByte)) != -1){ //如果不是最后一个就一直读
fos.write(ecgByte);
}

上传图片
看工具包upserver