Boot Drive

K

Ken Kast

I'm creating a workstation app that should work under Win, UNIX and Linux.
I need to find the boot drive. File.listRoots gives me all the roots; how
can I find out which one I booted from?

Thanks.
 
C

Christophe Vanfleteren

Ken said:
I'm creating a workstation app that should work under Win, UNIX and Linux.
I need to find the boot drive. File.listRoots gives me all the roots; how
can I find out which one I booted from?

Thanks.

You can't using pure Java.

You could parse /etc/fstab under *nix systems to find the /boot partition
(if there is one, otherwise use /).

And then there is still no guarantee that you actually booted from that
partition, as you could have booted from a cdrom or floppy for example.
 
K

Ken Kast

Christophe Vanfleteren said:
You can't using pure Java.

You could parse /etc/fstab under *nix systems to find the /boot partition
(if there is one, otherwise use /).

And then there is still no guarantee that you actually booted from that
partition, as you could have booted from a cdrom or floppy for example.

OK, then maybe I set my bar too high. I'm most familiar with Windows,
so let me use it as an example. I want to have a canonical place to
put a log file. Under windows I'd put in the root on c. What I
really need to do is find the primary harddrive/partition, the c
drive. I don't know if other OS's have that same concept. Even if it
was a windows-only app I wouldn't want to hardwire "c". And that
wouldn't even make sense for a non-windows file system. So I want
some harddrive "attribute" common to all the OS's. Is there anything
Java can provide?

Ken
 
C

Christophe Vanfleteren

Ken said:
OK, then maybe I set my bar too high. I'm most familiar with Windows,
so let me use it as an example. I want to have a canonical place to
put a log file. Under windows I'd put in the root on c. What I
really need to do is find the primary harddrive/partition, the c
drive. I don't know if other OS's have that same concept. Even if it
was a windows-only app I wouldn't want to hardwire "c". And that
wouldn't even make sense for a non-windows file system. So I want
some harddrive "attribute" common to all the OS's. Is there anything
Java can provide?

Ken

Just put it in the directory of the user which is running the program.

Try new File(System.getProperty("user.home")) to get the home dir. You now
know where to find the file, and it is usable on any OS.

And putting files directly in the root of a system is not a good idea. On
any *nix system, only root (administrator) can write to / (which is the
root directory, of which all others, even those on other drives, are
subdirs of).

You could also make the directory configurable offcourse, and pass it to
your program using a property (java -DmyLogFile=c:\file.log, then use
System.getProperty("myLogFile")), or putting the location in a property
file.
 
V

Virgil Green

Ken Kast said:
Christophe Vanfleteren <[email protected]> wrote in message

OK, then maybe I set my bar too high. I'm most familiar with Windows,
so let me use it as an example. I want to have a canonical place to
put a log file. Under windows I'd put in the root on c. What I
really need to do is find the primary harddrive/partition, the c
drive. I don't know if other OS's have that same concept. Even if it
was a windows-only app I wouldn't want to hardwire "c". And that
wouldn't even make sense for a non-windows file system. So I want
some harddrive "attribute" common to all the OS's. Is there anything
Java can provide?

Store it relateive to your application and find it using
this.Class.GetResource() or something similar.

Alternately, have the user configure it via a .properties file. You might
allow them to specify the preferred location via a preferences dialog or
something.

I'd find my .properties file the same way I suggested finding the log
file... with GetResource().

- Virgil
 
M

mromarkhan

peace.
I don't know if I can help you.
public class GetJuice
{
public static void main(String [] args)
{
String omarshome = System.getProperty("user.home");
System.out.println(omarshome);
java.util.Properties props = System.getProperties();
props.list(System.out);
}
}
 
G

Guest

Ken said:
OK, then maybe I set my bar too high. I'm most familiar with Windows,
so let me use it as an example. I want to have a canonical place to
put a log file. Under windows I'd put in the root on c.

I'm currently running on Windows and I have not a C disk.
My boot disk is G.
And I do not want any log file directly on the G: root!

- Dario
 

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,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top