上传照片时出现 java.io.IOException: fail to upload 怎么办?怎么能够传上去
答案:2 悬赏:80 手机版
解决时间 2021-02-10 12:57
- 提问者网友:你挡着我发光了
- 2021-02-10 09:34
上传照片时出现 java.io.IOException: fail to upload 怎么办?怎么能够传上去
最佳答案
- 五星知识达人网友:鱼忧
- 2021-02-10 10:27
我也遇到此问题
全部回答
- 1楼网友:拾荒鲤
- 2021-02-10 10:35
byte peekbyte() throws ioexception {
int val = peek();
if (val < 0) {
throw new eofexception();
}
return (byte) val;
}
import java.io.eofexception;
import java.io.file;
import java.io.fileinputstream;
import java.io.fileoutputstream;
import java.io.ioexception;
import java.io.objectinputstream;
import java.io.objectoutputstream;
import java.io.randomaccessfile;
import java.io.serializable;
import java.util.arraylist;
import java.util.iterator;
import java.util.list;
class school{
private string name;
public list list;
public school(string name) {
this.name = name;
}
public list getallstudents() {
if(list == null)
list = new arraylist();
return list;
}
}
class student2 implements serializable{
private static final long serialversionuid = 1l;
private string name;
private int id;
public student2(string name, int id) {
this.name = name;
this.id = id;
}
@override
public string tostring() {
return "student2 [name=" + name + ", id=" + id + "]";
}
}
public class test01 {
public static void main(string args[]) throws exception{
file f=new file("d:"+file.separator+"test2.txt");
// randomaccessfile rdf=new randomaccessfile(f,"rw");
school sch = new school("西南大学");
student2 s1=new student2("zhangsa",30);
student2 s2=new student2("mnc",30);
sch.getallstudents().add(s1);
sch.getallstudents().add(s2);
iterator iter=sch.getallstudents().iterator();
objectoutputstream oos= null ;
oos = new objectoutputstream(new fileoutputstream(f)) ;
while(iter.hasnext())
{
student2 a5=iter.next();
oos.writeobject(a5) ;
}
object obj = null ; // 接收读取的内容
objectinputstream ois =null;
try{
ois = new objectinputstream(new fileinputstream(f)) ; // 实例化对象输入流
while(true)//直接用while(true),让读取操作一直进行
{
obj = ois.readobject(); //循环下面的数据
system.out.println(obj);
}
}catch(eofexception e){ //此处捕获eofexception
system.out.println("已经达到文件末尾");
}catch(ioexception e){
e.printstacktrace();
}
finally{
if(ois!=null)
{
ois.close() ; // 关闭
}
if(oos!=null)
oos.close();
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯