Writing OS filesystem independent Java programs...

P

Patrick Ma

Hi,

What is your preferred way to write OS filesystem independent Java program?
The Java program will need to both read and write to files. This is a server
side Java program that has total access to the filesystem.

For reading files, one can use the "resource anchor class" and
Class.getResourceAsStream(). This is nice because the root path is
represented by the "resource anchor class" instead of "C:\" or "\usr".
However, this is a read only solution. Is there a "write" counter-part to
this?

Do you prefer to specify a root path, such as "C:\" or "\usr" in your
program and have a Singleton access method to return the root path based on
looking up the OS property in System?

What other ways can you think of?
Thanks.
 
M

Michael Borgwardt

Patrick said:
Do you prefer to specify a root path, such as "C:\" or "\usr" in your
program and have a Singleton access method to return the root path based on
looking up the OS property in System?

*Bad* solution.
What other ways can you think of?

- File.listRoots()
- File.createTempFile()
- have a configuration file where the path must be specified
 
C

Chris Smith

Patrick said:
What is your preferred way to write OS filesystem independent Java program?
The Java program will need to both read and write to files. This is a server
side Java program that has total access to the filesystem.

For reading files, one can use the "resource anchor class" and
Class.getResourceAsStream(). This is nice because the root path is
represented by the "resource anchor class" instead of "C:\" or "\usr".
However, this is a read only solution. Is there a "write" counter-part to
this?

Do you prefer to specify a root path, such as "C:\" or "\usr" in your
program and have a Singleton access method to return the root path based on
looking up the OS property in System?

What other ways can you think of?

Generally speaking, you'll provide a base directory in a configuration
file, so it can be customized to the server. If you want to generally
examine the entire filesystem, then File.getRoots() is a good starting
point.

More details will depend on exactly what you're trying to accomplish.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
D

Dave Monroe

Patrick Ma said:
Hi,

What is your preferred way to write OS filesystem independent Java program?
The Java program will need to both read and write to files. This is a server
side Java program that has total access to the filesystem.

For reading files, one can use the "resource anchor class" and
Class.getResourceAsStream(). This is nice because the root path is
represented by the "resource anchor class" instead of "C:\" or "\usr".
However, this is a read only solution. Is there a "write" counter-part to
this?

Do you prefer to specify a root path, such as "C:\" or "\usr" in your
program and have a Singleton access method to return the root path based on
looking up the OS property in System?

What other ways can you think of?
Thanks.

Take a look at System.getProperties().

A lot of Java's portability depends on that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top