![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
so would this be right?
BufferedReader buf = new BufferedReader (new FileReader ("User Data/Master List.txt"));
while ((currentLine = buf.readLine ()) != null)
{
filedata += currentLine;
StringTokenizer st = new StringTokenizer (filedata);
while (st.hasMoreTokens ())
{
str = st.nextToken ();
asd = str;
}
}
buf.close (); |
|
|
|
|
|
#12 | ||
|
Professional Programmer
|
No, it wouldn't be right
Quote:
Quote:
import java.io.*;
import java.util.*;
class SearchFile{
public SearchFile(String txt, String file){
int count = 0; // count how many times the word apears
String currentLine;
try{
BufferedReader bfr = new BufferedReader(new FileReader(file));
while ((currentLine = bfr.readLine ()) != null){
//take one line at a time and split it in words
StringTokenizer str = new StringTokenizer(currentLine);
while (str.hasMoreElements()){
String element = str.nextToken();
//see for every element if it's the one you're searching for.
if(txt.equalsIgnoreCase(element)){
count++;
}
}
}
System.out.println("Word found "+count+" times");
}catch(IOException e){
e.printStackTrace();
}
}
}
class MainSearch{
public static void main(String[] args){
SearchFile srch= new SearchFile("Romy","file.txt");
}
}
__________________
Don't take life too seriously, it's not permanent ! |
||
|
|
|
|
|
#13 |
|
Programming Guru
![]() |
public String stripHTMLTags( String message ) {
StringBuffer returnMessage = new StringBuffer(message);
int startPosition = message.indexOf("<"); // encountered the first opening brace
int endPosition = message.indexOf(">"); // encountered the first closing braces
while( startPosition != -1 ) {
returnMessage.delete( startPosition, endPosition+1 ); // remove the tag
startPosition = (returnMessage.toString()).indexOf("<"); // look for the next opening brace
endPosition = (returnMessage.toString()).indexOf(">"); // look for the next closing brace
}
return returnMessage.toString();
}a bit of code i ripped from what i am doing now, this code works btw ![]() if you use the indexOf() method it finds the position in the string where the string contains the string you are looking for, or returns -1 if it is invalid. edit: anopying the code tags messed up my tabbing ![]()
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#14 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
ok and how would i list the files in a directory?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|