|
-
November 3rd, 2005, 05:26 PM
#1
How to loop read thru a text file
I am totally new to Java programming...
I need to be able to do the following:
1) Read the records from a text (TXT) file, the data is in the following format:
Username1, AuthenticationID1
Username2, AuthenticationID2
...
2) Present the user with a simple interface to be able to select a specific Username
3) Once a Username is selected, the corresponding AuthenticationID should be captured in a variable; let's assume the AuthenticationID record in the text file is 1234567890 as dictated by the user selecting the associated Username
4) Take this variable (i.e. 1234567890) and place it in the AuthenticationID in the following code in my java file (i.e. AuthenticationID is 3981983721 in the JAVA file):
SearchStringTo = CAMID("\3981983721\")
Note: I need the 3981983721 replaced with the one selected from the text file, which is 1234567890, such that the final result would be the modification to the above line in my JAVA file:
SearchStringTo = CAMID("\1234567890\")
5) Thus, my SearchStringTo variable would now carry the number as selected by the user which originated from the read text file.
I'm not sure if what I'm asking is easily doable.
I've gone as far as attempting to read my text file, but I have no idea what I am doing (I downloaded this code off a tutorial Web Site:
import java.io.*;
class FileReadTest {
//--------------------------------------------------< main >--------//
public static void main (String[] args) {
FileReadTest t = new FileReadTest();
t.readMyFile();
}
//--------------------------------------------< readMyFile >--------//
void readMyFile() {
String record = null;
int recCount = 0;
try {
FileReader fr = new FileReader("authid_list.txt");
BufferedReader br = new BufferedReader(fr);
record = new String();
while ((record = br.readLine()) != null) {
recCount++;
System.out.println(recCount + ": " + record);
}
} catch (IOException e) {
// catch possible io errors from readLine()
System.out.println("Uh oh, got an IOException error!");
e.printStackTrace();
}
} // end of readMyFile()
} // end of class
Any scraps of info would be hugely appreciated.
Thanks so much in advance,
Shawn
-
November 3rd, 2005, 05:39 PM
#2
Re: How to loop read thru a text file
 Originally Posted by shawnmandel
I am totally new to Java programming...
I need to be able to do the following:
1) Read the records from a text (TXT) file, the data is in the following format:
Username1, AuthenticationID1
Username2, AuthenticationID2
...
I'll recommend the StreamTokenizer.
2) Present the user with a simple interface to be able to select a specific Username
Creating the user interface in Java is a pain. The sooner you start, the sooner it'll be over.
3) Once a Username is selected, the corresponding AuthenticationID should be captured in a variable; let's assume the AuthenticationID record in the text file is 1234567890 as dictated by the user selecting the associated Username
Maybe you should store the Username and AuthenticationID in a Map or something.
4) Take this variable (i.e. 1234567890) and place it in the AuthenticationID in the following code in my java file (i.e. AuthenticationID is 3981983721 in the JAVA file):
SearchStringTo = CAMID("\3981983721\")
Note: I need the 3981983721 replaced with the one selected from the text file, which is 1234567890, such that the final result would be the modification to the above line in my JAVA file:
SearchStringTo = CAMID("\1234567890\")
SearchStringTo = CAMID(String.format("%1$s", AuthenticationID));
5) Thus, my SearchStringTo variable would now carry the number as selected by the user which originated from the read text file.
Your SearchStringTo variable doesn't carry a number. It's carrying a string. That's an important distinction when determining what to do with the parsed data.
I'm not sure if what I'm asking is easily doable.
I think this is easily doable but your requirements are rather vague.
I know how to build. What to build is a completely different story.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|