Advertisement

06.04.2007 at 07:23AM PDT, ID: 22611077
[x]
Attachment Details

Java - File Location Configuration on Unix Box

[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!

6.2
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
Answered By: marklorenz
Expert Since: 05/31/2007
Accepted Solutions: 169
Computer Expertise: Guru
marklorenz has been an Expert for 1 year 7 months, during which he has posted 377 comments and answered 169 questions. marklorenz is just one of 172 experts in the Java Editors & IDEs Zone. 1 expert collaborated on this answer, which was graded a "B" by the asker.
 
 
 
 
20081119-EE-VQP-47