stringTokenizer

I'm using a StringTokenizer to separate a list of filenames and id's(based on ";") that I get back from a database. My System.out.println looks like below

Results Before stringTokenizer: testfile.txt,78;testfile2.txt,79;testfile3.txt,80;textfile4.txt,81

Results After stringTokenizer:

testfile.txt, 78

testfile2.txt, 79

testfile3.txt, 80

testfile4.txt, 81

What I want to do next is the use a method that I have to rename each filename and fileid (the method adds the same character to the front of each) without having to hardcode each filename and id. Is there a way to do that for each line that i get back from the tokenizer?

[680 byte] By [The_Real_E.T.a] at [2007-11-27 1:37:02]
# 1
String s="testfile.txt,78;testfile2.txt,79;testfile3.txt,80;textfile4.txt,81";String [] array=s.split(";");And now you have an array to do your changes... :)
J@A@V@Aa at 2007-7-12 0:47:11 > top of Java-index,Java Essentials,Java Programming...
# 2
You can use regular expression to split them up.even numbers are filenamesodd numbers are fileids
rym82a at 2007-7-12 0:47:11 > top of Java-index,Java Essentials,Java Programming...
# 3

that sounds like it could work....how could i do that. maybe i could show you the method that i am using

DirIO do = new DirO("filename","location","fileid","/");

do.makeVis();

the location and the last "/" will always be the same, put i want to add the filename and fileid based on each line i get back from my tokenizer

The_Real_E.T.a at 2007-7-12 0:47:11 > top of Java-index,Java Essentials,Java Programming...
# 4
hi,after getting tokens u can tokenize further for "," as a delimeter.it can be a way to get the job done.
Yogesh.Nandwanaa at 2007-7-12 0:47:11 > top of Java-index,Java Essentials,Java Programming...
# 5

> that sounds like it could work....how could i do

> that. maybe i could show you the method that i am

> using

>

> DirIO do = new

> DirO("filename","location","fileid","/");

> do.makeVis();

>

> the location and the last "/" will always be the

> same, put i want to add the filename and fileid based

> on each line i get back from my tokenizer

I don't know where that DirO object came from, but this is how the split method works:

String text = "testfile.txt,78;testfile2.txt,79;testfile3.txt,80;textfile4.txt,81";

String array[] = text.split(",|;");

if(array.length%2 != 0)

throw new RuntimeException("array has an uneven number of elements!");

for(int i = 0; i < array.length-1; i+=2) {

System.out.println("file="+array[i]+", id="+array[i+1]);

}

prometheuzza at 2007-7-12 0:47:11 > top of Java-index,Java Essentials,Java Programming...
# 6
when i add "," as second delimiter and get back file_id on 1 line and filename on the next:9999file1.txt9900file2.txtis there a way to say that the value of odd lines = file_idand even lines = filename
The_Real_E.T.a at 2007-7-12 0:47:11 > top of Java-index,Java Essentials,Java Programming...
# 7
for (int i=0;i<array.length;i++)if (i%2==0)// you have an IDelse //you have a file>
J@A@V@Aa at 2007-7-12 0:47:11 > top of Java-index,Java Essentials,Java Programming...