C
csz
Unregistered / Unconfirmed
GUEST, unregistred user!
向jsp页面传文件流,该页面该怎么接收并保存在本地?
小弟刚接触java,各位大虾,请多多帮忙~~
我的代码如下,该如何修改呢?
package uploadbean;
import java.io.*;
import java.util.Random;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
public class myUpload {
private String uploadDirectory;
private String filename;
byte Linebyte[] = new byte[4096];
byte outLinebyte[] = new byte[4096];
public myUpload() {
uploadDirectory = "c://" ;
filename = "test.txt";
}
public void uploadFile(HttpServletRequest req)
throws IOException, ServletException
{
// setCharacterEncoding(req.getCharacterEncoding());
// setContentType(req.getContentType());
SaveStream(req.getInputStream());
}
public void SaveStream(ServletInputStream servletinputstream) throws IOException, ServletException{
File file = new File(uploadDirectory, filename);
FileOutputStream fileoutputstream = new FileOutputStream(file);
fileoutputstream.write(servletinputstream.readLine(Linebyte, 0, Linebyte.length));
fileoutputstream.close();
}
}
小弟刚接触java,各位大虾,请多多帮忙~~
我的代码如下,该如何修改呢?
package uploadbean;
import java.io.*;
import java.util.Random;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
public class myUpload {
private String uploadDirectory;
private String filename;
byte Linebyte[] = new byte[4096];
byte outLinebyte[] = new byte[4096];
public myUpload() {
uploadDirectory = "c://" ;
filename = "test.txt";
}
public void uploadFile(HttpServletRequest req)
throws IOException, ServletException
{
// setCharacterEncoding(req.getCharacterEncoding());
// setContentType(req.getContentType());
SaveStream(req.getInputStream());
}
public void SaveStream(ServletInputStream servletinputstream) throws IOException, ServletException{
File file = new File(uploadDirectory, filename);
FileOutputStream fileoutputstream = new FileOutputStream(file);
fileoutputstream.write(servletinputstream.readLine(Linebyte, 0, Linebyte.length));
fileoutputstream.close();
}
}