• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

method problem

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay fellas, i have come a long way on my journey. ive been trying to write a class which contains a method searchFile(). all i want that method to do is: any text file that gets passed to my search method, read it in and check to see if it contains the two strings in it at all. I am close but I am missing something, any help is greatly appreciated thanks.
import java.io.*;
import java.util.*;
public class PunchFile{
private String xString = new String("00001X000001X057000000000CO083100");
private String zString = new String("07573Z07573");
static File fPun = new File("C:\\workfiles\\datafile.001");
public static void main(String args[]){
PunchFile pf = new PunchFile();
pf.searchFile(fPun);
int searchFile(file fFile){
fFile = fPun;
Vector vFile = new Vector();
BufferedReader brSearch;
String sOneLine;
brSearch = new BufferedReader(new FileReader(fPun));
sOneLine = brSearch.readLine();
while (sOneLine != null) {
vFile.add(sOneLineline);
sOneLineline = brSearch.readLine();

while(sOneLine != null){
if (!vFile.contains(xString)) {
System.out.println("no x line");
}
else if (!vFile.contains(zString)) {
System.out.println("no z line");
}
else {
System.out.println("this file has both lines");
}
}//end while2
line = br.readLine();
}//end while1
}//end method
}//end main
}//end class
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When do you update the value of sOneLine?

If you don't change the value of sOneLine (which is supposed to be an immutable string), you'll get stuck in an infinite loop.
Also, why do you declare searchFile inside main instead of just inside PunchFile?

And, it isn't necessary to set fFile to fPun; this is done for you when you pass the parameter.
HTH,
Jason

[This message has been edited by Jason Ford (edited August 13, 2001).]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm, i dont understand the method decaralation parts either
 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic