Iam facing a problem with uploding .xls files using struts.iam able to upload .txt,.doc,.csv files.If i try to upload .xls files there are uploading to the loacl drive say for eg.C or D drive.If i try to open the file from the drive location(C or D), iam not able to view the content.
my code for upload is,
**** htFileList is a HashTable which contains the files to be uploaded. **** path is a sting array which contains the paths where the files will be uploaded.
**** I used MultipartRequestHandler for storing the file sin HashTable.
Added UBB code tags for readability [ October 27, 2006: Message edited by: Merrill Higginson ]
I've uploaded many an .xls file using the Struts upload function and have not had this problem. The obvious suspect is the code you're using to create the Hashtable of FormFiles. I'd suggest you try an experiment to see if this is the case or not.
Code up a simple JSP that uploads a single file, and code a simple ActionForm to go along with the page that has a single FormFile property. Then just let Struts populate the FormFile normally and use similar code to what you posted above to write the file to disk. If this file is readable and the others are not, then you know the problem is in your code that creates the HashTable.
The problem is with your choice of BufferedWriter. This class is used for text files. For binary files you will want to use BufferedOutputStream. Also, you should move the opening and closing of your output file outside of the loop so you don't have to do this for every byte that you read from the input stream.
Joined: Feb 08, 2006
FYI, I got a private message from Aswinle saying that the following code worked:
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(pathinfo+"\\"+htFilesList.get("file"+(fileCount)), true));
Cool! I am sure I am not the only one that thinks that the java.io package is a bit confusing. It always seems like there is 10 different ways to do everything. The "InputStream/OutputStream" versus "Reader/Writer" naming convention seems like a bad design decision.