Help coderanch get a
new server
by contributing to the fundraiser

Pete Dawn

Greenhorn
+ Follow
since Sep 28, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Pete Dawn

Can you give me an example. I need to find a quick fix to this one.

Thanks.
15 years ago
Hi everyone,

I have a list in the following format,
A, B, C, 3
X, Y, Z, 2
J, K, L, 4
P, L, M, 1

Now I need to sort this list based on the 4th index (integer). Can somebody tell me how can I go about it.

I've tried Collections.sort, but it doesnt help me when I have numbers greater than 9, like 10, it puts 1,10... etc.

Thanks.
15 years ago
the properties file is just a simple text file and not a java properties file.
15 years ago
hi guys,

am working on file which contains the following many lines of data,
Message, String1, String2, String3, String4

Now string1, string2, string3, string4 are alphanumeric codes. now i need to read a properties text file which contains the strings associated with these codes.
eg. "String1"="Test Message"

so i need to parse my file and replace all occurences of codes with their respective strings (from the properties file).

am not sure how should i go about it. please help. thanks.
15 years ago
also its not hard coded X and Y. i mean the 2nd field has to be same in the file. so i need to group all same 2nd fields in the file and then process them. how would i do that. thanks.
15 years ago
i am currently saving the individual records in a class (time, date, string etc). now i should create a second class or create a new list.

not sure?
15 years ago
i have tried to implement the Comparator class.

and have also written a compare method. but am not sure how i would implement it.

please help. thanks.
15 years ago
hi guys,

i have a file which looks something like this,
111, X, 12, 34, 56
111, Y, 12, 34, 56
122, X, 12, 34, 56
122, Y, 12, 34, 56
133, X, 12, 34, 56
133, Y, 12, 34, 56

now i have parsed this data and am storing individual records in a class and then accessing them and everything is fine.

but i need to further group this data based on the 2nd record (X and Y). and then I need to process the individual records in different ways. i mean i need to somehow group the records and then parse them. please help. thanks.
15 years ago
Yes i think thats the kinda things i am after. can you provide some sample code. thanks.
17 years ago
have got this so far, but its only reading b name="test0" and not its child nodes. i basically want to parse the entire file and obtain individual element attributes.

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("settings.xml"));

doc.getDocumentElement ().normalize ();

Node n;
NodeList nodes = doc.getDocumentElement().getChildNodes();

for( int i=0 ; i<nodes.getLength(); i++ )
{
n = nodes.item( i );

if( n.getNodeType() == Node.ELEMENT_NODE )
{
if( n.getNodeName().equals( "b" ) )
{
NamedNodeMap attrs = n.getAttributes();
String x = attrs.getNamedItem("name").getNodeValue();
String y = attrs.getNamedItem("value").getNodeValue();
}
}
else
{
}
}>
17 years ago
guys,

i have a xml file with this format,
<a>
<b name="test0" value="0">
<d>
<c name="test1"/>
<c name="test2"/>
<g>
<e name="test3" value="1"/>
<f name="test4" value="2"/>
</g>
</d>
</b>
</a>

basically i have a file which is multiple levels deep and has
corresponding element attributes. can somebody please help me out to
read the individual attributes from each line. i am new to XML in java and am having a tough time with it. thanks.
17 years ago
guys and gals,

i am trying to create some environment variables from within my java app.

now i have two probs,
1. how should i create a environment variable from within my app.
2. how should i edit the environment variable value.

now what i have done is, i have created the environment variable manually from withing My Computer and then tried to edit it. i am able to retreive the value and even edit it but surprisingly when i go back to my computer to check the new value, its still the old value.

Properties p = ReadEnv.getEnvVars();
String varLoc = p.getProperty(TEST_VAR);

so my question is how can i edit it in such a way that its reflected in my computer too.

and second question, how can i create an environment variable and even delete it if needed.

thanks.
17 years ago
the command works fine when i execute it from the command prompt and it performs the backup. but i am not sure of whats the best way of running the same command from within my java code. so the command is correct, but the syntax from within java code is incorrect. any help guys.
17 years ago
yes the command works from the command line standalone. but i am not sure how to run it from within my java code. i am sure that my command is correct, my syntax for using that command is incorrect.

any help.
17 years ago
guys,

I am trying to implement a postgres DB backup function from within my web application. Now so far I have got this,
Process p = Runtime.getRuntime().exec( new String[] {
"cmd.exe",
"/E:1900",
"/C",
"C:\\Program Files\\postgresql\\8.1\\bin\\pg_dump -i -h localhost -p 5432 -U postgres -F t -b -v -f C:\\Test.backup TESTDB"});

But it isnt working. I am constantly getting an error that c:\program location does not exist, i guess thats coz program files has a space in it.

Can somebody please give me the right syntax (right way) of performing this function.

Thanks.
17 years ago