Tou fazendo uma página jsp que faz o upload de um arquivo, peguei o utilitário fileupload do site da apache, e na especificação tem um código assim:
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
DiskFileUpload fu = new DiskFileUpload();
// maximum size before a FileUploadException will be thrown
fu.setSizeMax(1000000);
// maximum size that will be stored in memory
fu.setSizeThreshold(4096);
// the location for saving data that is larger than getSizeThreshold()
fu.setRepositoryPath("/tmp");
List fileItems = fu.parseRequest(req);
// assume we know there are two files. The first file is a small
// text file, the second is unknown and is written to a file on
// the server
Iterator i = fileItems.iterator();
String comment = ((FileItem)i.next()).getString();
FileItem fi = (FileItem)i.next();
// filename on the client
String fileName = fi.getName();
// save comment and filename to database
...
// write the file
fi.write("/www/uploads/" + fileName);
}
Na penúltima linha, fi.write("/www/uploads/" + fileName);, está errada, pois, de acordo com a API do FileItem, tem de ser da seguinte maneira:
public void write(java.io.File file)
throws java.lang.Exception
E no caso está como java.lang.String ao invés de java.io.File, tentei executar e deu erro de incompatibidade, depois modifiquei para:
fi.write(new File("/www/uploads/" + fileName));
Assim é possível pois a API de java.io.File diz que o construtor pode receber um path como String, mas mesmo assim deu um monte de exception, alguém pode me ajudar, desde já fico muito grato.