Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - File getName method behaviour on different OS!

 
Thread Tools Search this Thread
Old 06-27-2003, 08:05 PM   #1
Default File getName method behaviour on different OS!


I try this code:
File file = new File(args[0]);
String filename = file.getName();
System.out.println("file name : " + filename);

I run it on windows with these arguments:
/opt/test/test1.txt
c:\windows\test2.txt

I got this:
file name : test1.txt
file name : test2.txt

If I run it on Linux I get this:
file name : test1.txt
file name : c:\windows\test2.txt

Why I don't get the same thing? I know it does not make sense to write
down a path that isn't in the system format. I will use an URL format
to get the real name…

Tom


Tom
  Reply With Quote
Old 06-27-2003, 08:07 PM   #2
Paul Tomblin
 
Posts: n/a
Default Re: File getName method behaviour on different OS!
In a previous article, (Tom) said:
>I try this code:
> File file = new File(args[0]);
> String filename = file.getName();
> System.out.println("file name : " + filename);
>
>I run it on windows with these arguments:
>/opt/test/test1.txt
>c:\windows\test2.txt
>
>I got this:
>file name : test1.txt
>file name : test2.txt
>
>If I run it on Linux I get this:
>file name : test1.txt
>file name : c:\windows\test2.txt
>
>Why I don't get the same thing? I know it does not make sense to write


Because on Windows, the forward slash and the back slash both work as path
separators, so "/opt/test/test1.txt" would be a file test1.txt in the path
\opt\test on the current drive. On the other hand, Linux allows
backslashes and colons in file names, so "c:\windows\test2.txt" would
indicate a file called "c:\windows\test2.txt" in the current directory.

Here is a part of an "ls" in my home directory:

cfs.zip crichton_faq dft-v330img.bin
cleanfeed-20010715.tgz c:\windows\test2.txt dickhead
clubtop5 datasources disk



--
Paul Tomblin <>, not speaking for anybody
"The question of whether a computer can think is no more
interesting than the question of whether a submarine can swim ."
E. W. Dijkstra


Paul Tomblin
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SONY DVD RW DW-G120A SOMETIMES FAILS...... atlantic965 DVD Video 0 06-18-2006 10:36 PM
problems backing up dvds Lawrence Traub DVD Video 11 09-27-2005 07:34 PM
Re: Ripping DVDs. Please answer the attached question. - Question.txt Stan Brown DVD Video 19 02-09-2005 11:19 PM
Burn process failed - help! Log file posted for help troubleshooting Michael Mason DVD Video 1 08-16-2004 09:24 PM
Pioneer A05 Problems Bill Stock DVD Video 8 11-28-2003 05:03 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46