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\\Bu
ild\\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[] populateStrArrayWithParame
ters(Strin
g 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(deLimi
ter);
if(index != -1)
{
key = strEachLine.substring(0, index);
if(index + 1 <= strEachLine.length())
{
value = strEachLine.substring(inde
x + 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