> Hi,
>
[quoted text clipped - 5 lines]
>
> MArcelo
sorry for the question, I have found the answer
System.out.println("OS version: "+System.getProperty("os.name"));
However i have another problem. I save files like a path on Windows into
a text file, but when I try to load them, there is an error.
This is the file
D:\MisArchivos\workspace\fingerprinting\config\words.txt
but the error is that I get:
D:MisArchivosworkspace-ingerprintingconfigwords.txt
How can I save files in a platform-independent way?
thankx
Marcelo
Oliver Wong - 10 Feb 2006 21:18 GMT
>> Hi,
>>
[quoted text clipped - 18 lines]
>
> How can I save files in a platform-independent way?
If you can create an instance of a File object representing the file
whose path is desired, you can call its toString() method to get a
string-representation of the path to that file.
- Oliver
M. Fernandez - 10 Feb 2006 21:50 GMT
>>> Hi,
>>>
[quoted text clipped - 24 lines]
>
> - Oliver
Isn't it better to use a File.toURI() representation of the File? I
would like to run my application either on Linux or on Windows...
thanx
Marcelo
Oliver Wong - 10 Feb 2006 22:35 GMT
> Isn't it better to use a File.toURI() representation of the File? I would
> like to run my application either on Linux or on Windows...
If you read the JavaDocs for toURI():
<quote>
The exact form of the URI is system-dependent. [...] Due to the
system-dependent nature of abstract pathnames, however, this relationship
typically does not hold when a file: URI that is created in a virtual
machine on one operating system is converted into an abstract pathname in a
virtual machine on a different operating system.
</quote>
So toURI() doesn't buy you much more than toString().
I you really want to pass File objects back and forth between operating
systems, then you should serialize the File object itself to some binary
format and transmit that.
If all you care about is your application running on any operating
system, without the need to communicate with another instance of the same
application on another operating system, toString() is good enough.
- Oliver
Roedy Green - 10 Feb 2006 21:58 GMT
>> This is the file
>> D:\MisArchivos\workspace\fingerprinting\config\words.txt
\ in a string literal must be doubled.
See http://mindprod.com/jgloss/file.html about system file separators
and http://mindprod.com/jgloss/literals.html about string literals.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Douwe - 10 Feb 2006 22:01 GMT
You probably entered the filename hardcoded in a String, that is:
String filename = "
D:\MisArchivos\workspace\fingerprinting\config\words.txt";
which should be
String filename = "
D:\\MisArchivos\\workspace\\fingerprinting\\config\\words.txt";
If you would like to make sure your code is platform independent then
don't write drive letters like C: and D:, these are windows specific.
Preferable the user can either configure the file location or the file
location is relative to a certain path (i.e new File("./test.txt")).
Luc The Perverse - 10 Feb 2006 21:51 GMT
>> Hi,
>>
[quoted text clipped - 18 lines]
>
> How can I save files in a platform-independent way?
You use single backslashes in a path name string, they will be considered
escape codes.
Instead of "D:\MisArchivos\workspace\fingerprinting\config\words.txt"
use "D:\\MisArchivos\\workspace\\fingerprinting\\config\\words.txt"\
It is clear that you are new to programming. Try not using a path at all,
and see where files go. You should be able to use this "working directory"
to keep your files in.
--
LTP
:)

Signature
LTP
:)
Chris Smith - 11 Feb 2006 05:40 GMT
> It is clear that you are new to programming. Try not using a path at all,
> and see where files go. You should be able to use this "working directory"
> to keep your files in.
Sorry, Luc, but I think that's really bad advice. In a GUI environment,
the current working directory is almost always an unclear concept to the
user, and it's not defined by any relevant specification. Applications
should not make use of the current working directory unless it's clearly
the intent of the user for it to do so, which implies that it's probably
a command line utility. Command line utilities are among the rarest
uses of Java applications, and in the few cases where they are written,
the author already knows, as a fact, that the CWD is required.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Luc The Perverse - 12 Feb 2006 06:03 GMT
>> It is clear that you are new to programming. Try not using a path at
>> all,
[quoted text clipped - 10 lines]
> uses of Java applications, and in the few cases where they are written,
> the author already knows, as a fact, that the CWD is required.
He;s tring to learn very basic programming concepts - my suggestion was to
get everything else working before worrying about platform independant
pathing. He is obviously on a windows box right now using a hard coded path

Signature
LTP
:)
Roedy Green - 10 Feb 2006 21:57 GMT
On Fri, 10 Feb 2006 22:15:52 +0100, "M. Fernandez"
<mache_1999@hotmail.com> wrote, quoted or indirectly quoted someone
who said :
>However i have another problem. I save files like a path on Windows into
>a text file, but when I try to load them, there is an error.
without showing code and quoting the text of the error messages, the
responses you get won't be much better than a palm reader could give
you.
If you need help with I/O the file I/O amanuensis will generate you
skeleton code for pretty well any purpose. See
http://mindprod.com/jgloss/fileio.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
ossie.moore@gmail.com - 12 Feb 2006 03:55 GMT
Note: you can refer to
"D:\MisArchivos\workspace\fingerprinting\config\words.txt" as
"D:/MisArchivos/workspace/fingerprinting/config/words.txt". ie.. File
file = new
File("D:/MisArchivos/workspace/fingerprinting/config/words.txt"); will
work. That said, I agree with the statement that using
File.pathSeparator (or it's peer, File.pathSeparatorChar) are more
reliable when building a path.
Note also, the reason
"D:\MisArchivos\workspace\fingerprinting\config\words.txt" becomes
"D:MisArchivosworkspace-ingerprintingconfigwords.txt" is because the
'\' char is an escape char in a quoted string. If you persist in using
the '\' char when building a file path, you need to escape it as
follows...
"D:\\MisArchivos\\workspace\\fingerprinting\\config\\words.txt"
On Fri, 10 Feb 2006 22:08:55 +0100, "M. Fernandez"
<mache_1999@hotmail.com> wrote, quoted or indirectly quoted someone
who said :
>I need to know if the virtual machine is working on linux or on windows.
>
>How can i do it with Java?
see http://mindprod.com/jgloss/helloworld.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
> Hi,
>
[quoted text clipped - 5 lines]
>
> MArcelo
If you really must define yor path in the code then try using
File.separator instaed of '\' or '/' as this will give you the file
separator for the OS you are running so making it platform indepedant.
> I need to know if the virtual machine is working on linux or on windows.
Java is available on *both*.
> How can i do it with Java?
Do what?

Signature
Darryl L. Pierce <mcpierce@gmail.com>
Homepage: http://mcpierce.multiply.com/
"McVeigh's lawyer got him the death penalty, which, quite frankly,
I could have done." - Jon Stewart
Dag Sunde - 11 Feb 2006 17:45 GMT
>> I need to know if the virtual machine is working on linux or on windows.
>
> Java is available on *both*.
Not the question...:
"...Working..." read: What os is it running under.
>> How can i do it with Java?
>
> Do what?
Check what OS his/hers app is running under at runtime.
Question answered earlier in the thread.

Signature
Dag.
Darryl L. Pierce - 12 Feb 2006 12:18 GMT
>>> I need to know if the virtual machine is working on linux or on windows.
>>
>> Java is available on *both*.
>
> Not the question...:
> "...Working..." read: What os is it running under.
Ah! My bad. Sorry.

Signature
Darryl L. Pierce <mcpierce@gmail.com>
Homepage: http://mcpierce.multiply.com/
"McVeigh's lawyer got him the death penalty, which, quite frankly,
I could have done." - Jon Stewart
I think System.getProperty("os.name") can help you ~~~~~