How to determine what OS your java prog is running on?

Is there a Java command to determine what OS your program is running on?
Yes it IS important -- because there are things that are OS-specific, such as valid characters for filenames.
I could just disallow ALL "shady characters", but then my program would be skipping a lot of GOOD files in Linux, which only disallows the '/' character.
http://www.linuxboxadmin.com/articles/tools-and-utilities/linux/mac/windows-file-name-friction.html
Any ideas how I should proceed?
Matthew

I assume, if it's looking at "ALL" files in a directory, that it is running in a loop, right? Well, put the try/catch in the loop, rather than around it, and let it throw an exception. Catch it and keep a list of files that didn't work. But then again, if you're talking about "reading" a file, this shouldn't be a problem, because if it is an invalid character, how did the file get there? and should it really be your worry?
As far as writing one with a character like that, let the user enter tha name he wants, attempt to create it, and if it fails ask for another, and for those filenames that you generate within the program, stick to the "safe" characters.

Similar Messages

  • How to determine path of your java program?

    hi,
    i have got some code to check what type of files are in my folders so that i can display an avaliable list of eg. save games.
    the problem is that the path of the program will change with each user that uses it cos they'll keep it somewhere else.
    so this wont work
    File f = new File("C:/Documents and Settings/Me/My Documents/GAME");is there a way to determine the whereabouts of the program thats running to change this path?
    ive already tried:
    File f = new File("");
    File f = new File("/");
    File f = new File("/GAME");but they dont work.
    thanks in advance

    Thats exactly what i needed thanks.
      import java.io.*;
       //Code by Roquefort
        public class Files
           public static void main(String[]args)
             new Files();
           public Files()
             System.out.println(System.getProperty("user.dir"));
             String dir = System.getProperty("user.dir");
             char slashChar = 92;
             char slashChar2 = 47;
             String slash = slashChar + "";
             System.out.println(dir.length());
             for(int i = 0; i < dir.length()-1; i++)
                if(dir.substring(i,i+1).equals(slash))
                   dir = dir.substring(0,i) + "/" + dir.substring(i+1,dir.length());
             System.out.println(dir);
             File f = new File(dir);
             String [] names;
             names = f.list();
             for(int a=0;a<names.length;a++)
                if(names[a].endsWith("GIF"))//Change file extension, or remove if for all files
                   System.out.println(names[a]);
       }

  • Have situation on a unprotected wireless when accessing I cannot get a router address.  I'm on system 10.6.8 on MacBook Pro summer 2009.  Any thoughts on how to determine what's up?

    Have situation on a unprotected wireless when accessing I cannot get a router address.  I'm on system 10.6.8 on MacBook Pro summer 2009.  Any thoughts on how to determine what's up?

    You have basically verified that the issue is NOT with your MBP, but with this particular Wi-Fi network. Even though it may be unsecured, the provider may have elected to configure it for MAC filtering. In this case I am referring to the MAC (Media Access Control) address and not your Mac laptop itself. If this has been enabled, your Mac would only be able to connect if the Mac's MAC address was added to that filter.

  • How to determine what Index is required by a query ?

    Hi all,
    In our application, we create some complex View with complex query.
    The question is : How to determine what Index is required by the query ?
    I try using SQL Tuning Advisor, but it seems I can only use it After running TOP SQL.
    Is there aniway to determine the Index even Before the query under heavy load/ top sql ?
    Thank you very much,
    xtanto

    You can run your explain plan to check the table access path. You can create an index and see if the optimizer is using the index. Then compare the costs. Creating index will help only in some occassion and you need to provide complete details of the requirement to come to a conclusion of which type of INDEX as well. In some occassions, B*Tree index is useful, in few DW applications, bitmap will work efficiently with columns of low cardinality.
    So it is again the task for you to look into this.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/toc.htm
    Cheers
    Sarma.

  • How to determine what prevents auto sleep?

    My iMac doesn`t go to sleep automatically, so my question is how to determine what prevents sleep?

    I, too, have just noticed this issue after I left my computer to secure empty trash. I thought my computer would enter sleep mode automatically, but when I returned to my home office to turn in for the night, I found that the computer had been on (with the monitor off) the entire evening. So much for "Energy Saver."
    I have been through as many of the threads covering this issue. I checked to see if there were any apps using the processor. None. I checked "Put the hard drive(s) to sleep when possible." I made sure Internet Sharing was unchecked. I even unchecked Bluetooth sharing or anything that would require some type of network or internet connection. Despite all this, the computer still does not go to sleep on it's own.
    I have just upgraded to Lion 10.7.3 on my iMac 2.4 Ghz Intel Core 2 Duo so this is definitely a continuing problem which has not been addressed since older theads dealing with early versions of Lion.
    Let's hope Mountain Lion will fix this.

  • How do you know if your apple warranty is run out on I phone so I can buy apple care

    How do you know if your apple warranty is run out on I phone so I can buy apple care

    Check Your Service and Support Coverage: Apple - Support

  • What are your options when you run out of hard drive space?

    What are your options when you run out of hard drive space? 

    I 110% agree, it is a disaster but it saves your mac until you recieve an external HD.
    Csound1 wrote:
    XcodeDeveloper wrote:
    I know but he just wanted options so I gave him one that helped me. If he filled up his HD a Gigabyte is sometimes a small miracle, exaggeration on small .
    OSX with 1G of free space is a disaster waiting to happen.
    Read this:

  • How to determine what card is in what slot of a PXIe-1073 unit programmab​le

    How can i programmable determine what card is in what slot of a PXIe-1073 unit I have a PXI-4063 and a PXI-2503 in a 1073 chassis. I use the DAQmx Device Product Type to to find the 2503 matrix card but it woun't return the 4065 product type.

    Hi cjp1,
    The KnowledgeBase article Programmtic PXI Slot Detection walks you through the steps to do this. There is also a community example called Read PXI an PXIe Card Serial Numbers Programatically that demonstrates the type of LabVIEW architecture you can use to do it. 
    You should first ensure that all of your modules can be identified and self-test in MAX. 
    In case the above hyperlinks don't work, you can copy-paste the addresses below:
    http://digital.ni.com/public.nsf/allkb/2342900AED0​2975A86256BD800764C8B
    https://decibel.ni.com/content/docs/DOC-20207
    Jeff Munn
    Applications Engineer
    National Instruments

  • How to Determine What Version of JDK I Have?

    Hi,
    How do I determine what version of the JDK or SDK is installed on our server?
    Thanks,
    Ken

    There isn't any readme or license file in the JDK folder. Our JDK is not direct from Sun, it came with WebSphere App Server, so maybe IBM left out such files. Anyway, the "java -fullversion" command works. Thanks!
    Ken

  • How to determine what's using data store temp space?

    How can one determine what's using data store temp space? We are interested to know what structures are occupying space in temp space and if possible what pid/process connected to TimesTen created them.
    Also, is there a procedure that will work if temp space is full?
    Recently one of our data stores ran of space. We we're unable to run commands like "monitor", "select * from monitor", "select count(*) from my_application_table", etc. These commands failed because they required temp space to run and temp space was full. We killed the application processes, this in turned freed up temp space, then we were able to run these queries.
    Ideally, we'd like to have a procedure to figure out what's using temp space when temp space is full.
    The other thing we could do is periodically monitor temp space prior to it filling to determine what's using temp space.

    That was my original thought, but once you click the slider track or thumb, and then enter a value in the text control, the clickTarget on the change event envoked by the change to the bound data (after entering a value in the text control) will be whatever slider element had last been clicked. If you've never clicked the slider, clickTarget=null. But once you've clicked the slider the clickTarget always has a value of "thumb" or "track", regardless of what triggered the change event.

  • How you tell what generation your iPod is

    how may I determine what generation an iPod touch is? says just say model A1509 on back

    my question is I have a 5G iPod and when making a playlist, how can I repeat the song a few times in a row in making the playlist.         the + can only be pressed once [and then not red or clickable].
    I went into edit playlist and pressed red repeat option on bottom left and options came up [cancel, repeat playlist, repeat song, repeat off] and I pressed repeat song option and it clicks and now has pink box. that looked promising but it still doesn't end up on the playlist. 
    I clicked on the repeat off option at top of list of options- it clicks, but stays the same- saying repeat off, and does not appear to do anything in terms of adding to a playlist on edit mode.
    I went into setting to try to see if it was locked somehow but could not find it.
    after trying to edit - add songs in [duplicate as above] I press the done bottom. but then see it has not added the songs I clicked pink box/repeat to original playlist.
    This is my first playlist since an old nano!

  • How Do I determine what version of Oracle I am running?

    Is there som sort of command that you can run in Oracle to determine what version you are running? I cannot find this anywhere!

    hi ken h r u ?
    i'm not a dba but from ur question i find the answer within 2 minutes
    try this query in SQLPlus
    select * from v$version ;
    and tell me what is the results .
    regards
    null

  • HRPAD00INFTY - How to determine what action the user took (IN_UPDATE)

    Greetings, Experts.
    I've been asked to modify an existing BAdI for infotype 0167. The existing code is in method IN_UPDATE.  FYI, we have to use this method (as opposed to, say, AFTER_INPUT) since we have to make sure the user completed the operation as we're modifying data in another infotype based on their action.
    As such, the  logic depends on what the user is doing, i.e., inserting, updating, delimiting or deleting a record. I was testing different scenarios in PA30 to see what the value of IPSPAR-ACTIO would be and got some puzzling results.
    For example, I used the Edit->Copy feature in PA30 to copy and then delimit an existing record and was expecting an ACTIO of "LIS9" (Delimit) but it was "MOD". Similarly, I used the trashcan to remove an existing record and got a "MOD" operation. Finally, I deleted another record the same way (trashcan icon) and this time it was "LIS1" which I found stupefying since that's not even a valid value according to the DDIC for data element ACTIO.
    I can't seem to get a consistent way to determine what the user is doing. What is the best practice?
    Thanks.

    Hi Steve,
    You can  try with IPSYST-IOPER Parameter Which is Showing the Right Values .
    Regards,
    Kishore.S

  • How to find what port the admin server is running

    how can I find out what port the admin server is running on a server?
    thanks,

    Hi
    Go to your domain root folder/config and open config.xml file in any editor. Search for the name of the admin server which is typically like AdminServer and under this tag see if you have a tag by name <listen-port>. If yes, then you should see the port number. If not, it means it is running at default port of 7001.
    If you have admin access, i hope when you login you will be giving url like http://adminhost:adminport/console. Now this adminport is the port on which admin server is running. If not, then check config.xml file.
    Thanks
    Ravi Jegga

  • How to set proxy authentication using java properties at run time

    Hi All,
    How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
    => Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
    import java.io.*;
    import java.net.*;
    public class DnldURLWithoutUsingProxy {
       public static void main (String[] args) {
          URL u;
          InputStream is = null;
          DataInputStream dis;
          String s;
          try {
              u = new URL("http://www.yahoo.com.au/index.html");
             is = u.openStream();         // throws an IOException
             dis = new DataInputStream(new BufferedInputStream(is));
             BufferedReader br = new BufferedReader(new InputStreamReader(dis));
          String strLine;
          //Read File Line By Line
          while ((strLine = br.readLine()) != null)      {
          // Print the content on the console
              System.out.println (strLine);
          //Close the input stream
          dis.close();
          } catch (MalformedURLException mue) {
             System.out.println("Ouch - a MalformedURLException happened.");
             mue.printStackTrace();
             System.exit(1);
          } catch (IOException ioe) {
             System.out.println("Oops- an IOException happened.");
             ioe.printStackTrace();
             System.exit(1);
          } finally {
             try {
                is.close();
             } catch (IOException ioe) {
    }However, it generated the following message when run behind the firewall:
    cd C:\Documents and Settings\abc\DnldURL\build\classes
    java -cp . DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
    at java.net.Socket.connect(Socket.java:452)
    at java.net.Socket.connect(Socket.java:402)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:320)
    at sun.net.www.http.HttpClient.New(HttpClient.java:315)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    I have also tried the command without much luck either:
    java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
    There is no problem pinging www.yahoo.com from this system.
    I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
    I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
    Java Control Panel - Use browser settings without success.
    Thanks,
    George

    Hi All,
    How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
    => Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
    import java.io.*;
    import java.net.*;
    public class DnldURLWithoutUsingProxy {
       public static void main (String[] args) {
          URL u;
          InputStream is = null;
          DataInputStream dis;
          String s;
          try {
              u = new URL("http://www.yahoo.com.au/index.html");
             is = u.openStream();         // throws an IOException
             dis = new DataInputStream(new BufferedInputStream(is));
             BufferedReader br = new BufferedReader(new InputStreamReader(dis));
          String strLine;
          //Read File Line By Line
          while ((strLine = br.readLine()) != null)      {
          // Print the content on the console
              System.out.println (strLine);
          //Close the input stream
          dis.close();
          } catch (MalformedURLException mue) {
             System.out.println("Ouch - a MalformedURLException happened.");
             mue.printStackTrace();
             System.exit(1);
          } catch (IOException ioe) {
             System.out.println("Oops- an IOException happened.");
             ioe.printStackTrace();
             System.exit(1);
          } finally {
             try {
                is.close();
             } catch (IOException ioe) {
    }However, it generated the following message when run behind the firewall:
    cd C:\Documents and Settings\abc\DnldURL\build\classes
    java -cp . DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
    at java.net.Socket.connect(Socket.java:452)
    at java.net.Socket.connect(Socket.java:402)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:320)
    at sun.net.www.http.HttpClient.New(HttpClient.java:315)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    I have also tried the command without much luck either:
    java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
    There is no problem pinging www.yahoo.com from this system.
    I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
    I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
    Java Control Panel - Use browser settings without success.
    Thanks,
    George

Maybe you are looking for

  • Removing Item from Finder Menu

    How do I remove an item from the Finder Menu? I have the clock, airport-thingy, and power info. There is also a character palette item. displayed as an american flag. How do I remove the character palette item from the menu?

  • CheckIn content

    Hi, I want to use filter which will check the file extension, size and comments (should not be null ) before check-in. If the file size is less than 50mb or extension is .txt or comment is null then the filter will not allow to check-in. I am using C

  • Fading a Photo

    How to fade a portion of a photo in photoshop elements 11?

  • How to disable the Time Machine prompt

    Even when Time Machine is turned off every time our students access firewire drives, they will be prompted by TM to backup. This will be confusing and inconvenient for everyone. Anyone have a solution? Thanks.

  • Alarms causing problems - should I reinstall?

    I have a Z22 and have been running Palm Desktop 4.2 on Windows XP Pro. Recently I was having trouble connecting for HotSync, so, following published  troubleshooting suggestions, I installed Palm 6.2 over 4.2. I was able to get my data back, but Palm