Advertisement

06.04.2007 at 07:23AM PDT, ID: 22611077
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Java - File Location Configuration on Unix Box

Tags: java, file, unix, location
Dear Experts,

I have the below Java Code and it seems to work fine when the specified path exists on my machine however when I deploy the code to a UNIX Box it doesnt work.

What I want to do is configure the code so that when I deploy this code onto a UNIX box I can specific a file as I have done on a normal pc in this code

package com.test.uk.eve;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

// Referenced classes of package com.test.uk.eve:
//            ResultItem

      
    implements Serializable
{

    private static HashMap FILE_HASH_MAP = new HashMap();
    private static String fileName = "C:\\Factory\\Projects\\Build\\file.txt";

    public Utilities()
    {
    }

    public ResultItem getResultem(String theAction, String msisdn, String erId)
    {
        String key = theAction + "-" + msisdn + "-" + erId;
        String value = getValueGivenKey(key);
        ResultItem resultItem = new ResultItem();
        String strValueArray[] = parseValue(value);
        if(strValueArray == null)
        {
            return null;
        } else
        {
            String responseCode = strValueArray[0];
            String responseText = strValueArray[1];
            resultItem.msisdn = msisdn;
            resultItem.responseCode = responseCode;
            resultItem.responseText = responseText;
            return resultItem;
        }
    }

    public String[] populateStrArrayWithParameters(String key)
    {
        String strArray[] = new String[3];
        String deLimiter = "-";
        if(key == null)
        {
            return strArray;
        }
        int index = key.indexOf(deLimiter);
        for(int counter = 0; index != -1 && counter <= 1 && !key.equals(""); counter++)
        {
            strArray[counter] = key.substring(0, index);
            if(index + 1 <= key.length())
            {
                key = key.substring(index + 1, key.length());
            }
            index = key.indexOf(deLimiter);
        }

        strArray[2] = key;
        return strArray;
    }

    public String[] parseValue(String value)
    {
        String strArray[] = new String[2];
        String deLimiter = "-";
        if(value == null)
        {
            return strArray;
        }
        int index = value.indexOf(deLimiter);
        if(index != -1)
        {
            strArray[0] = value.substring(0, index);
        } else
        {
            strArray[0] = value;
            strArray[1] = null;
            return strArray;
        }
        if(index + 1 <= value.length())
        {
            strArray[1] = value.substring(index + 1, value.length());
        }
        return strArray;
    }

    public static String getValueGivenKey(String key)
    {
        if(key == null)
        {
            return null;
        } else
        {
            return (String)FILE_HASH_MAP.get(key);
        }
    }

    public static ArrayList readFile()
        throws Exception
    {
        File file = new File(fileName);
        FileReader fileReader = new FileReader(file);
        BufferedReader br = new BufferedReader(fileReader);
        ArrayList list = new ArrayList();
        for(String strLine = br.readLine(); strLine != null; strLine = br.readLine())
        {
            list.add(strLine);
        }

        br.close();
        fileReader.close();
        return list;
    }

    public static HashMap popualateHashMap()
        throws Exception
    {
        ArrayList list = readFile();
        if(list != null)
        {
            String deLimiter = "=";
            for(int i = 0; i < list.size(); i++)
            {
                String strEachLine = (String)list.get(i);
                String key = "";
                String value = "";
                if(strEachLine != null)
                {
                    int index = strEachLine.indexOf(deLimiter);
                    if(index != -1)
                    {
                        key = strEachLine.substring(0, index);
                        if(index + 1 <= strEachLine.length())
                        {
                            value = strEachLine.substring(index + 1, strEachLine.length());
                        }
                    } else
                    {
                        key = strEachLine;
                        value = null;
                    }
                    FILE_HASH_MAP.put(key, value);
                }
            }

        }
        return FILE_HASH_MAP;
    }

    static
    {
        try
        {
            popualateHashMap();
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}

I hope someone can help

Regards
Pungwick
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Pungwick
Solution Provided By: marklorenz
Participating Experts: 1
Solution Grade: B
Views: 38
Translate:
Loading Advertisement...
06.04.2007 at 07:42AM PDT, ID: 19208884

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.04.2007 at 08:19AM PDT, ID: 19209221

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.04.2007 at 08:55AM PDT, ID: 19209567

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.04.2007 at 09:16AM PDT, ID: 19209718

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.04.2007 at 10:08AM PDT, ID: 19210170

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.04.2007 at 10:24AM PDT, ID: 19210299

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.04.2007 at 10:38AM PDT, ID: 19210395

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.04.2007 at 10:51AM PDT, ID: 19210509

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.04.2007 at 11:10AM PDT, ID: 19210654

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.08.2007 at 12:33PM PDT, ID: 19441015

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
06.04.2007 at 07:42AM PDT, ID: 19208884
You should not be hardcoding slashes in paths - they are different between Windows and Unix.  Instead, you should use:

String pathSeparator = System.getProperty("path.separator");
String fileSeparator = System.getProperty("file.separator");

See how these are used here:
http://www.javaworld.com/javaworld/jw-10-1998/apptowin32/UserInfoApplet.java

Mark
 
06.04.2007 at 08:19AM PDT, ID: 19209221
Could you give me an example on how I can change my code to reflect what you have said?

Because using the function pathseperator I can replace the "\" making the path of the file neater but how would this help then when it comes to specifiying a UNIX path?

Hope you can help

regards
Pungwick
 
06.04.2007 at 08:55AM PDT, ID: 19209567
Mark,

I have tried the below:

public String fileSeparator = System.getProperty("file.separator");
private static String fileName = fileSeparator + "test" + fileSeparator + "file.txt";

Is this correct? The question here is how is the value of the fileSeperator defined?

Will this value be configured automatically dependent on Operating System?

Any ideas?

 
06.04.2007 at 09:16AM PDT, ID: 19209718
That is correct - you use it to construct your path.  The actual character used depends on the system you are running the code on.  So, Windows uses "\", Unix"/", Macintosh ":".  You should not have to do more than use the System.getProperty("file.separator") and it will run on all OSs.

You can read more here:
http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter09/fileClass.html

Mark
 
06.04.2007 at 10:08AM PDT, ID: 19210170
Mike,

I was wonderimg how could I use the same concept but by using class loader?

I mean right now the value of the file is being hard coded right? is it possible to specify the name of the file instead and then load the file in by searching using the Classpath?

Unsure how to do this your help is very welcomed

Regards
Pungwick
 
06.04.2007 at 10:24AM PDT, ID: 19210299
Mike,

What I am trying to do is to specifiy the file name only and this picked up by using the Classpath.

Do you know how I can do this?

Regards
PUngwick
 
06.04.2007 at 10:38AM PDT, ID: 19210395
Picking up a file based on the classpath is different than pulling in an OS-specific character for referencing a file. You can reference either relative or absolute to the installation root.

Relative would look like:
..\images\sample.gif

Absolute would look like:
myproject\images\sample.gif

Has your problem been resolved?
Mark
 
06.04.2007 at 10:51AM PDT, ID: 19210509
Mark

How do I do this via the classpath? Say I have specfied the Jar files in my class path and part of the Jars is the file that I am interested in loading.

Do you get what I mean?

regards
Pungwick
 
06.04.2007 at 11:10AM PDT, ID: 19210654
The files in the jar have their own path - if you open a jar file (e.g. using 7-zip or winzip), you will see that all the files are still referred to by their complete path.

If the jar is on the classpath, it will look in the jar. But it can still be referenced relative or absolute.

You can read about this here:

Relative and Absolute Paths
http://www.extropia.com/tutorials/unix/relative.html

relative paths
http://www.javaworld.com/javaworld/javatips/jw-javatip109.html

absolute path names, and relative path names
http://www.d.umn.edu/~gshute/unix/unix.html

Mark
Accepted Solution
 
07.08.2007 at 12:33PM PDT, ID: 19441015
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Accept: marklorenz {http:#19210654}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Venabili
EE Cleanup Volunteer
 
 
20080236-EE-VQP-29