Great, glad to hear. It was a pleasure. Kind Regards Schalk Neethling Volume4.Development.Multimedia.Branding emotionalize.conceptualize.visualize.realize Tel: +27125468436 Fax: +27125468436 email:[EMAIL PROTECTED] web: www.volume4.co.za
:: -----Original Message----- :: From: Rhino [mailto:[EMAIL PROTECTED] :: Sent: Thursday, July 24, 2003 4:12 PM :: To: Jakarta Commons Users List :: Subject: Re: [FileUpload] File Separator question :: :: Thanks Schalk, that worked fine! My servlet can now upload a file from :: Windows to a Linux server (or a Windows server) without mangling the name; :: the file name is "frotz1.txt" in both cases and the file is in the correct :: directory. :: :: I really appreciate your help! :: :: Rhino :: :: ----- Original Message ----- :: From: "Schalk" <[EMAIL PROTECTED]> :: To: "'Jakarta Commons Users List'" <[EMAIL PROTECTED]> :: Sent: Thursday, July 24, 2003 2:34 AM :: Subject: RE: [FileUpload] File Separator question :: :: :: Rhino :: :: :: :: I use the bit of code below to determine the actual filename of the file :: being uploaded: :: :: :: :: StringTokenizer tokenizer = new StringTokenizer(fileName, "\\, :, /"); :: :: :: int amount = tokenizer.countTokens(); :: :: for (int i = 0; i < amount -1; i++) { :: :: tokenizer.nextToken(); :: :: } :: :: String currentFile = tokenizer.nextToken(); :: :: :: :: 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 = :: "/var/www/vhosts/nexroot/webapps/Nexroot/ssl/FTP/files/"; :: :: :: :: Then write the file to disk as follows: :: :: :: :: File diskFile = new File(serverFolder, currentFile); :: :: :: :: item.write(diskFile); :: :: :: :: item.delete(); :: :: :: :: Hope this helps you out. :: :: :: :: Kind Regards :: :: Schalk Neethling :: :: Volume4.Development.Multimedia.Branding :: :: emotionalize.conceptualize.visualize.realize :: :: Tel: +27125468436 :: :: Fax: +27125468436 :: :: email:[EMAIL PROTECTED] :: :: web: www.volume4.co.za :: :: :: :: -----Original Message----- :: From: Rhino [mailto:[EMAIL PROTECTED] :: Sent: Thursday, July 24, 2003 1:36 AM :: To: commons-user :: Subject: [FileUpload] File Separator question :: :: :: :: I need some help to get my FileUpload servlet to work "cross-platform". :: :: :: :: 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. :: :: :: :: 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. :: :: :: :: 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-dir\\ :: 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. :: :: :: :: 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. :: :: :: :: 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? :: :: :: :: I am running Tomcat 4.1.24 on both the Windows XP and Linux boxes. The Linux :: box is running Mandrake 9.1. :: :: :: :: :: Rhino :: --- :: rhino1 AT sympatico DOT ca :: "If you want the best seat in the house, you'll have to move the cat." :: :: :: :: --------------------------------------------------------------------- :: To unsubscribe, e-mail: [EMAIL PROTECTED] :: For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
