Creating a platform-independent path

Hello,
I'm working on an application that will be used on different O/S, that reads files stored by the user from anywhere on the system. The problem I have is that I need the paths to be stored such that the user session files still work when moved across computers. e.g.,
for the file on my system with absolute path on my windows machine, which has only one partition (on C):
C:\Documents and Settings\userDir\My Documents\wig\prototype\fileName.jpgnew File(pathToFile).getAbsolutePath() and new File(pathToFile).getPath() - will give the above. However trying to retrieve the same file on any other computer, with the same location from the root, even windows with multiple partitions, say, that has the application on the F drive, say, will fail, because the path cd be, say:
F:\Documents and Settings\userDir\My Documents\wig\prototype\fileName.jpgMoving to MAC or Linux will obviously also fail. However if I can save the file location as:
/Documents and Settings/userDir/My Documents/wig/prototype/fileName.jpgthen it will work on any of these machines and O/S provided that the directory containing said file has the same path to the root from the working directory. Now the latter condition can be replicated on any of the end user machines. However I've searched through the forums and the JDK but cannot find a way of doing this via Java, unless I convert the original absolute path to a string and manually edit that string to arrive at the final. Is there something available that I'm missing - string manipulation, while it will work, is not the optimal solution. FYI - the user selects the file from a file browser, so on save the application calls :
File resource = fileChooser.getSelectedFile();
... resource.getAbsolutePath()
... and so on...Aba-Sah

.. there is no way to tell the relative path from where the program is runno, I don't meant "no way" programmatically - I do know how to do that. What I meant is that I am not able to restrict where on the end user's machine the running program is installed - this is dependent on their system set-up - so it isn't possible to determine the relative path from that location to the directories containing the data.
altho' having said that i think i know where ur going, will need to think about that, it may work...if i restrict relative path of the data directory from the working directory rather than (relative) path from the root.
Edited by: aba-sah on Oct 30, 2008 5:55 AM

Similar Messages

  • The symbol "/" in properties file is platform independent ?

    Hi!
    In my properties file I set many patha to my any resources(path to my icons, path to my user XML file and so on):
    # content of my properties file
    userSettingsPath=config/usersettings.xml
    baseNameImages=/resources/images/
    # end
    As you see in path I use symbol "/" to create path.
    This work in Windows platform. Is this will work in other platforms?
    Is symbol "/" is platform independent?

    It works as a separator in Java, actual separators in the OS may vary.

  • Why java is platform independent ?

    what is the meaning of java is platform independent ? is it just because of java code can be run in windows/linux/unix platform ? but then C/C++ also can be run in windows/linux/unix . so why those are not called platform independent ?
    why java is called platform independent ?

    c/c++ creates object code . similary java creates bytecode . java uses interpreter JVM to execute . similary c/c++ object code also executes in any platform. so where is the real difference ?
    the classes do not need to be recompiled for different platforms. what do u mean by this ? ".....classes ( i.e bytecode) dont need recompilation ..." .....ok....but same thing is true for C/C++ object code also !! they also dont need recompilation.
    where is the difference ?

  • Oracle Universal Installer response files and platform independency

    Hi all,
    The Oracle Universal Installer is a platform-independent system, to what extent are Oracle Universal Installer response files platform-independent? For sure it's not completely platform-independent, because path definitions aren't portable - Windows versus Linux for example. My hope is that all possible variables within response files are exactly the same as on different platforms. Also the possible values for the variables should be portable, except for the path definitions, of course.
    Can anyone confirm that my thoughts are true?
    Durk

    Hi,
    This problem frequently occurs because of the wrong DISPLAY settings. Please perform the steps on a X-term terminal screen;
    1) under root user
    2) xhost +
    3) su - ora<sid>
    4) echo $DISPLAY
    5) setenv DISPLAY <client ip>:(result of echo $DISPLAY) (for example setenv  DISPLAY 192.168.1.100:0.0)
    6) xclock (test X-Client)
    If it works then you will be able to run "./runInstaller", for example
    cd /oracle/stage/102_64/database/Disk1/SAP
    ./RUNINSTALLER
    You can check the [installation guide|https://websmp204.sap-ag.de/~sapidb/011000358700000359232008E], also. Search for "4.4.3 Running the Oracle Universal Installer" title and read the details,
    Best regards,
    Orkun Gedik

  • Software development is platform independent?

    ORACLE Database has features like having database triggers, stored procedures / functions, table or column level constraints. So are they proprietary functionality of ORACLE. Can I build some of these above-mentioned features using standard SQL? Am I violating the proprietary law?
    The current trend of software development is platform independent? How to achieve this?
    null

    I have had this problem before, I think you can use
    something like:
    System.getProperty("path.separator");But I am not at work right now to look, so sorry. Im
    sure someone else could confirm this.No, it's file.separator:
    file.separator      File separator ("/" on UNIX)
    path.separator Path separator (":" on UNIX)
    line.separator      Line separator ("\n" on UNIX)
    But better use File.separator instead of a hardcoded string -> compiler will complain at typos.
    -Puce

  • Platform-independent handling of newlines in captions

    LR 3 should handle newlines in captions in a platform-independent manner.
    Currently on Windows, captions containing newlines represented by a single newline character ("\n") don't display properly in the Metadata panel, both in the Default and Large Caption presets.  Only newlines represented DOS-style ("\r\n") display properly.   If you enter a newline in the Large Caption preset, then it gets stored in DOS-style format ("\r\n").
    This creates problems when moving metadata to and from other programs and platforms. For example, Photoshop Elements generates a single newline character ("\n") for newlines in metadata.
    It would be better for LR to do what most modern Windows programs do when faced with the need for platform-independent data: Accept either format ("\r\n" or "\n") and display it properly as a single newline.  When newlines are entered into the Metadata panel, store them as a single "\n" character.

    The current behavior is a littler messier than I thought: I you enter a caption with newlines via the Metadata panel, they are stored in the catalog in DOS format (\r\n).  If you then do Save Metadata To File, the newlines get stored in Unix format (\n), which is good.  But if you then do Read Metadata From File, the Unix-format newlines replace the DOS-format nelines in the catalog, and they no longer display properly.
    This is more properly called a bug than a feature request, so I'll file a bug report.

  • Platform independency...any chance ?

    hi...java code (.class files ) are platform independence. It is supposed to run any platform.(i believe this) [ // it is fine in different  windows machine ].
    However, i was in argue with my friend..... He told that each platform (windows,Unix,Macintosh) have different JVM . so there is a chance that the class file may be rejected by the JVM in different platform.
    is it true ?
    if Yes.......then independency is lost !!! i can not call it is a pure platform independent.......are people trying for any remedy ?

    There are many different JVMs. Sun makes JVMs, IBM makes JVMs, M$ used to make JVMs, I think Blackdown makes JVMs, etc.
    As long as a JVM matches the spec, then a given class file is portable across different VMs. Just like if I create a Word doc on the PC, I can read it with word on my Mac.
    BUT (you knew there was going to be a "but", didn't you), there are different versions of VMs and the spec has changed over the years. Just like MS Word from 1990 probably won't read a document you create with the MS Word that you buy today, similarly you need to make sure the version of your class file is no newer than the VM. If the class file is an older version than the VM, it will generally work--they're backward compatible that way. Or is it forward compatible.
    Also, there are things that are legal Java code that won't necessarily translate from one platform to another that well. GUI stuff can be slippery that way, I understand. Some other things too, but I forget what.
    Is Java perfectly platform independent in that any class file generated anywhere anytime is guaranteed to run on any other VM? No, of course not.
    Is it easy to create applications that you can run with no changes on Mac, Windows, Linux, Solaris, and maybe others that I'm not aware of? Absolutely. Many of the apps I've developed in the last few years have been developed and unit-tested on Windows (and even Mac to some extent) and run on Linux or Solaris, without me even needing to think about it. (Not that you never need to think about it, but it's not an overriding concern.)

  • Webinar (Aug 11): How to create Cross-Platform Automated GUI Tests for Java Apps

    Join Squish expert, Amanda Burma, and learn how to create cross-platform automated GUI tests for your Java applications!
    Register here (multiple time slots)
    August 11th 2014
    Duration: 30 minutes plus Q & A
    This webinar will cover:
    General Squish for Java overview
    Automating BDD Scenarios
    Executing Cross-Platform Automated GUI Tests
    Interacting with Java application objects, properties & API
    See you there!
    Unable to attend? Register and we'll send links to future events and access to our webinar archive following the event.
    Webinar schedule
    Learn more about Squish
    Evaluate froglogic squish

    <property name="messaging.client.jar.path" value="Location in your local drive" />
    <property name="messaging.client.jar.name" value="nameOfYourFile.jar" />

  • Create Indesign book from paths in an excel sheet

    Hello All
    I have started to learn some scripting, and want to know if it is possible to read information from Excel sheet? In this case it is paths to Ind files.
    Today we are working with several documents which we compile into a book, this to create custom-made manuals for our customers. The script I'm looking for or will try to create will use these paths from the excel sheet to compile an Indesign book.
    Any tips where I can find information about similar tasks.
    Please respond

    Thanks for your advices.
    So if I understood it right it is impossible for Java or VB through Indesign to access information located within sheets in an Excel document. That is too bad.
    We don't have the possibility to convert the .xls to for example .csv, becouse of .csv does not support more than one sheet. An SQL database could be a possible solution, but this shouldn’t either work?
    What I don’t really understand is why you can merge information from an excel sheet into an Indesign page, but not collect strings from an excel sheet when running a script.

  • Java platform independent.what is a platform?

    This question has been haunting me for a long time.
    When we say Java is platform independent,what does the term platform
    indicate?
    I think it is Processor+Operating System.
    But people talk only of Operating System as platform.
    A processor has its own instruction set that is different from that of other processors.An executable code on one processor doesn't run on another processor,whatever may be the operating system.
    Java code is platform independent because it is just compiled to byte code and that byte code is interpreted and run on a JVM.Here the JVM is different for different platforms.
    My question is:
    consider two platforms:
    Intel Pentium+MS Windows.
    and AMD Athlon+MS Windows.
    Is the same JVM used for both these platforms?or not?WHY?
    If only Operating System is Considered as platform,what happens to the underlying processor?

    <troll style="flamesuit: on;">Java is not plateform inderpendent, java runs on one plateform, the Java Platform.</troll>
    The "Intel / AMD + MS Windows" is two forks of one plateform, the x86 / Windows plateform.
    You could extends the x86/Windows JVM to include Intel extras in such a way that it would not run on AMD/Windows.
    One way you could define a plateform is as a binary format, processor intuction set and public API.
    So java == .class format, bytecode and the java.* packages
    and Linux x86 == ELF, x86 and POSIX (plus others, such as X)
    and FreeBSD x86 == ELF, x86 and POSIX (plus others, such as X)
    and Cygwin == ELF, x86 and POSIX (plus others, such as X)
    and Windowsx86 == PE, x86, MFCs
    But does that mean Linux, FreeBSD and Cygwin are the same plateform, well kind-of, they are all unix-sqe, and in some cases the binarys are interchangable (a small plug in to FreeBSD will let you run Linux software, the same sort of thing is aviable to Solaris, and some very small (hello world-level) will actually run (I've seen this in the case of a Linux HelloWorld on a BeOS machine).

  • Verify that the database is created with the correct path  specification

    Dear All
    When I installed DB2 9.1 with SP4 on windows 2003 64 bit,I use Configuration Assistant tool which is problem
    SQL1031N  The database directory cannot be found on the indicated file system.  SQLSTATE=58031
    Explanation:
    The system database directory or local database directory could
    not be found.  A database has not been created or it was not
    cataloged correctly. 
    The command cannot be processed. 
    User Response:
    Verify that the database is created with the correct path
    specification.  The Catalog Database command has a path parameter
    which specifies the directory where the database resides. 
    sqlcode :  -1031
    sqlstate :  58031
    Thanks

    Hi Phuc,
    Could you please validate, that the database TST is located in driver H: ?
    If the database is there, you find a directory with the name of your instance under the H: drive, inside this directory, you must find a NODE0000 directory and finally inside the NODE0000 directory there must be a SQL0000? directory, where ? is a number.
    You get your instance name from the environment variable DB2INSTANCE or simply by the execution of:
    db2 get instance
    If there is no SQL0000? directory at all, this means the database is located somewhere else.
    If there is SQL0000? directory in that drive, you can perform the following:
    db2 CATALOG DB TST AS TST ON H:
    And provide the error message, if any.
    Hope this helps
    Best regards, Edgardo

  • Java is   NOT   Platform Independent ????????

    Hai.
    My friend told ...
    we can able to say java is platform independent.
    but
    in one company (software anaylist) ask
    talk about java is not platform independent...
    so how its possible..
    plz i want clear cuts...
    even i search in google also.. but i cant get clearlly.........
    yours
    advance happy pongal and upcomming festivals
    drvijayy2k2

    >
    A quick example I recently encountered of platform
    dependence was in character encoding/decoding. Have
    a look at how Solaris, Linux and Windows print out
    the full range of bytes when they are encoded as
    Strings. There are lots of little differences, happy
    discovering.This is a good illustration. By default java uses the character encoding which it believes to be in general use on the platform it's running on, but you can specify the character encoding explicitly. So, by default, the Java program addapts it's exact behaviour to the platform.
    Is "a platform independant" program one which produces the same file format on systems which will interpret that file format different ways? Or is it one that generates a file format that will produce equivalent results on two different systems?
    There's a similar dilema with "look and feel" (i.e. window gadgets etc.). Should a platform independant program use the same look and feel on systems whose native look and feel is different, or should it "blend in"?
    Java leaves these choices to the programmer.

  • How do u say java is platform independent

    how do u say java is platform independent.....when a .class file for a program cannot be executed in another system with no java installed in it.......

    Pictograms are language independent (sort of)
    do you expect them to work in the land of the blind?

  • Platform independency

    I have developed an implementation of High Availability Servers using Java in Linux. But the problem is it runs only in Linux because I have used the System class to execute a native OS command "ipconfig eth0 192.168.0.0.123" to change the Ip of the system.Is there any way to go around this so that the code becomes purely platform independent?
    One option is to detect the OS that is currently running and execue the appropriate System command using a switch statement.So is it possible to detect the underlying OS?If so , what is the command for changing IP in Mac OS, Windows....and any others which u can think of.
    HELP.

    Here is some basic code I wrote a LONG time ago:
         public static final int OSTYPE_WINDOWS = 1;
         public static final int OSTYPE_WINNT = 2;
         public static final int OSTYPE_WINCE = 3;
         public static final int OSTYPE_LINUX = 4;
         public static final int OSTYPE_MAC = 5;
         public static final int OSTYPE_SOLARIS = 6;
         public static final int OSTYPE_NETWARE = 7;
         public static final int OSTYPE_OS2 = 8;
         public static final int OSTYPE_UNKNOWN = 9;
         private static int type = OSTYPE_UNKNOWN;
              @return an integer identifying the OS (one of the OSTYPE constants)
         public static int getOs()
              if(type == OSTYPE_UNKNOWN){
                   String osname = System.getProperty("os.name").toLowerCase();
                   if(osname.indexOf("windows") != -1){
                        if(osname.indexOf("nt") != -1 || osname.indexOf("2000") != -1 || osname.indexOf("xp") != -1){
                             type = OSTYPE_WINNT;
                        } else if(osname.indexOf("ce") != -1){
                             type = OSTYPE_WINCE;
                        } else {
                             type = OSTYPE_WINDOWS;
                   } else if(osname.indexOf("linux") != -1 || osname.indexOf("bsd") != -1){
                        type = OSTYPE_LINUX;     
                   } else if(osname.indexOf("mac os") != -1 || osname.indexOf("macos") != -1){
                        type = OSTYPE_MAC;
                   } else if(osname.indexOf("solaris") != -1){
                        type = OSTYPE_SOLARIS;     // could also be old freebsd version
                   } else if(osname.indexOf("netware") != -1){
                        type = OSTYPE_NETWARE;
                   } else if(osname.indexOf("os/2") != -1){
                        type = OSTYPE_OS2;
                   } else {
                        type = OSTYPE_UNKNOWN;     
              return type;
         }

  • Why java is called platform independent? "write once, run anywhere" code...

    I do have a answer for this. Please shed some light whether i am right or wrong.
    When you say java as platform independent, it means that, any java program once compiled to java class can be transferred to anyother machine(say, from windows to unix) can be executed, provided the destination machine has JVM.
    where as, in C/C++, if we transfer the object files from one machine to another machine, they will not be executed and they have to be re-compiled in the other machine.
    Am i correct?
    please, do give me your idea on this...
    thanks...

    Thanks george !

Maybe you are looking for