Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 8090 invoked from network); 24 Jul 2003 06:34:32 -0000 Received: from ctb-mesg1.saix.net (196.25.240.73) by daedalus.apache.org with SMTP; 24 Jul 2003 06:34:32 -0000 Received: from DELL530 (rrba-bras-194-87.telkom-ipnet.co.za [165.165.194.87]) by ctb-mesg1.saix.net (Postfix) with ESMTP id 749ED77BD for ; Thu, 24 Jul 2003 08:34:40 +0200 (SAST) From: "Schalk" To: "'Jakarta Commons Users List'" Subject: RE: [FileUpload] File Separator question Date: Thu, 24 Jul 2003 08:34:32 +0200 Message-ID: <002801c351ad$a78d4030$0100a8c0@DELL530> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0029_01C351BE.6B161030" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4510 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 In-Reply-To: <00ef01c35173$1ced0490$0d02a8c0@athlon> X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_0029_01C351BE.6B161030 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Rhino =20 I use the bit of code below to determine the actual filename of the file being uploaded: =20 StringTokenizer tokenizer =3D new StringTokenizer(fileName, "\\, :, /"); int amount =3D tokenizer.countTokens(); =20 for (int i =3D 0; i < amount -1; i++) { tokenizer.nextToken(); =20 } =20 String currentFile =3D tokenizer.nextToken(); =20 I then store the folder to which I want the file to be written as a = public String at the top of my servlet i.e. public String serverFolder =3D "/var/www/vhosts/nexroot/webapps/Nexroot/ssl/FTP/files/"; =20 Then write the file to disk as follows: =20 File diskFile =3D new File(serverFolder, currentFile); =20 item.write(diskFile); =20 =20 item.delete(); =20 Hope this helps you out. =20 Kind Regards Schalk Neethling Volume4.Development.Multimedia.Branding emotionalize.conceptualize.visualize.realize Tel: +27125468436 Fax: +27125468436 email:schalk@volume4.co.za web: www.volume4.co.za =20 -----Original Message----- From: Rhino [mailto:rhino1@sympatico.ca]=20 Sent: Thursday, July 24, 2003 1:36 AM To: commons-user Subject: [FileUpload] File Separator question =20 I need some help to get my FileUpload servlet to work "cross-platform". =20 It works okay when uploading a file from a Windows machine to a Windows server but it misbehaves when I try to upload a file from a Windows = machine to a Linux server; it isn't setting the file name properly. =20 In a Windows->Windows scenario, the file I am uploading is something = like C:\original-dir\original-subdir\my.file. My servlet uses lastIndexOf(File.separator) to find the file name proper, e.g. my.file, = and then concatenates it to the end of the path where I want the file stored = in the server, e.g. C:\stored-dir\stored-subdir\my.file. The servlet saves = the file successfully and when I look at the C:\stored-dir\stored-subdir directory in my file system, the file name is my.file, exactly as I = want. =20 In a Windows->Linux scenario (i.e. uploading a Windows file to a Linux server), the servlet stores the file in the desired directory but it has = its full original name, e.g. C:\original-dir\original-subdir\my.file, not = just my.file. That means that the full file name of the uploaded file is something along the lines of /home/rhino/tomcat4/webapps/FileUploadServlet/SDAC-upload/C:\\original-di= r\\ original-subdir\\my.file. Clearly, that is not desireable; I want the uploaded file name to be /home/rhino/tomcat4/webapps/FileUploadServlet/SDAC-upload/my.file. =20 It seems clear to me that the file separator is the problem here. When = the servlet is running in Linux, it determines the value of file.separator = to be '/' while the file being uploaded is in Windows which has a = file.separator of '\'. The lastIndexOf(File.separator) therefore never finds the file = name proper and saves the entire path in the name, not just the last bit. =20 I'm not so sure what to do about it. Do I need to have my code determine = the OS from which it is getting the file which is being uploaded or is there some other technique I need to use? How would I determine the OS from = which I'm uploading? I know that I can get the OS of the server from the Java system property "os.name" but how do I get the OS which is the source of = the file upload? =20 I am running Tomcat 4.1.24 on both the Windows XP and Linux boxes. The = Linux box is running Mandrake 9.1. =20 Rhino --- rhino1 AT sympatico DOT ca "If you want the best seat in the house, you'll have to move the cat." ------=_NextPart_000_0029_01C351BE.6B161030--