Results 1 to 7 of 7
4Likes Thread: Scanner doubt
- 11-09-2012, 04:58 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
Scanner doubt
Hello, first of all sorry for my English. I'm trying to do a program to read a file using Scanner. The problem is that I need to read what is the content of each line twice and while I use entrada.nextLine() it jumps to the next line. Here it is a part of the program. Thanks.
public static void cargaDatosP(){
Scanner entrada= null;
try {
entrada = new Scanner (new FileInputStream("personas.txt"));
} catch (FileNotFoundException e) {
System.out.println("Error abriendo el fichero");
System.exit(-1);
}
while(entrada.hasNextLine()){
String[] campos=new String[10];
for(int i=0;entrada.hasNextLine();i++) { //Here I need to stop and go back to the while when I find a "*" in the file
campos[i]=entrada.nextLine();
}
- 11-09-2012, 05:00 PM #2
Re: Scanner doubt
If you need to examine the content of whatever is returned by nextLine(), simply store it in a String value and do whatever you want with it.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-09-2012, 05:23 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
Re: Scanner doubt
ok, thanks, that's solved, now the problem is that when I compare the String I've used with a "*" it doesn't match with it, though when I print the content of the String it appears "*". do u know why does it happen?
I've heard sth in class about putting "\\*" instead or sth like that.
- 11-09-2012, 05:26 PM #4
Re: Scanner doubt
You'll have to post the code you're using to match the String. Are you using a method from the String class? Are you using Patterns?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-09-2012, 05:27 PM #5
Re: Scanner doubt
How are you doing your string compare? Not with == I hope?
- 11-09-2012, 05:30 PM #6
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
Re: Scanner doubt
lol solved, I was doing it with ==
thanks a lot for the quick answers
- 11-09-2012, 05:43 PM #7
Similar Threads
-
a doubt
By Thia in forum New To JavaReplies: 13Last Post: 11-24-2009, 02:26 AM -
have doubt
By ras_pari in forum Advanced JavaReplies: 3Last Post: 10-01-2009, 09:51 AM -
doubt
By Chris555 in forum NetworkingReplies: 0Last Post: 08-05-2009, 02:58 PM -
Doubt
By winkodes in forum Enterprise JavaBeans (EJB)Replies: 2Last Post: 12-20-2008, 08:34 PM -
doubt in jms
By veena in forum Enterprise JavaBeans (EJB)Replies: 2Last Post: 01-05-2008, 01:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks