Find the answer to your Linux question:
Results 1 to 7 of 7
i have written a code to retrive the file system information in c... can i use java to call that module and execute? or is there a way to access ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2006
    Location
    india
    Posts
    36

    java and file system


    i have written a code to retrive the file system information in c... can i use java to call that module and execute? or is there a way to access our file system using java?

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    why must you use java to call your c program?
    you can just call it in your shell like any other shell commands.

    prompt#> ./yourprogram

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    The answer to your question is yes.

    Assuming that this module is its own executable program, you can use the Runtime class:
    http://java.sun.com/j2se/1.4.2/docs/...g/Runtime.html

    Basically, the code will look something like:
    Code:
    Process otherCommand = Runtime.getRuntime().exec("newcommand");
    
    System.out.println("newcommand's output:");
    
    // ignoring exception-handling for brevity
    BufferedReader bfrRead = new BufferedReader(otherCommand.getInputStream());
    
    while(bfrRead.ready())
        System.out.println(bfrRead.getLine());
    
    bfrRead.close();
    So basically, we execute the other command with the exec() method in the Runtime class. We can then access the command's streams through the Process method returned by exec().

    If you need to utilize C code or C libraries in Java, you can do so using the Java Native Interface (JNI). I unfortunately have no experience with it, so I can't help with that.

  4. #4
    Linux User
    Join Date
    Aug 2005
    Location
    Italy
    Posts
    401
    Why don't execute directly C code in a JAVA program?

    http://java.sun.com/j2se/1.4.2/docs/guide/jni/
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (http://counter.li.org)

  5. #5
    Linux User
    Join Date
    Oct 2004
    Location
    /dev/random
    Posts
    404
    What kind of filesystem information are you looking for that is not provided by java.io.File and friends?

    AFAIK, these classes should be enough if you just want to traverse a filesystem and create/delete files/directories.

    If you need lower level access (like accessing the superblock of a filesystem or inode table of the filesystem) then there is no API in java - you'll have to do it in C only.
    Or wait...
    maybe that should be possible to implement in Java as well..
    Just what LTOOLS used to do.. (Or did it just have a GUI frontend in Java?? )
    The Unforgiven
    Registered Linux User #358564

  6. #6
    Just Joined!
    Join Date
    Aug 2006
    Location
    india
    Posts
    36
    i know that it can be done by that but i want a extra gui which C cannot support me... so i want java to use as a front end....

  7. #7
    Just Joined!
    Join Date
    Aug 2006
    Location
    india
    Posts
    36
    yeah... i can understand a bit of wat u told... i will try out and reply... anyway thank u!!!!!!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •