我正在通过编写此代码在线程中上传文件
import java.io.*;
public class FileUploadThread extends Thread {
File f1, f2;
String fileName;
InputStream stream;
byte[] b = new byte[1024];
public FileUploadThread(File f1, File f2, InputStream stream, String filename) {
System.out.println("external class file name--->" + filename);
this.f1 = f1;
this.f2 = f2;
this.stream = stream;
this.fileName = filename;
}
public void run() {
try {
f2 = new File(f1, fileName);
OutputStream w = new FileOutputStream(f2);
int res = stream.read(b);
System.out.println("res = "+res);
while (res >= 0) {
for (int i = 0; i < res; i++) {
w.write(b);
}
res = stream.read(b);
System.out.println("res--->" + res);
}
} catch (Exception e) {
System.out.println("In the run method of the thread");
e.printStackTrace();
}
}
}
它向我展示了ArrayIndexOutOfBoundsException
。