> equals() is the right method, but you'll have to do a not-null check
> first, to see whether the object you're invoking it on is not null.
> However, I would expect empty lines to return "", not null. Can you
> post some code?
>
> Also look for the idiom "some string".equals(varString);
ok, but the object is not null, because until it does not find the null
line returns the right string.
String line = "";
BufferedReader in = null;
in = new BufferedReader(new FileReader("DatasetPiccolo.txt"));
String key = null;
while (line != null)
String readed = getTag(line);
if (readed == "authors")
{
key = getValue(line);
System.out.println(authors);
}
getTag is a method for delete some characters from the string. getValue
is for extract the text that I want.
Hendrik Maryns - 07 Aug 2006 09:44 GMT
Elbrethril schreef:
>> equals() is the right method, but you'll have to do a not-null check
>> first, to see whether the object you're invoking it on is not null.
[quoted text clipped - 14 lines]
>
> if (readed == "authors")
"authors".equals(readed)
> {
> key = getValue(line);
> System.out.println(authors);
> }
as I suggested.
H.
P.S. ‘readed’ is very odd English. It is ‘read’, pronounced like the
colour.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Elbrethril - 07 Aug 2006 09:57 GMT
Hendrik Maryns ha scritto:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 32 lines]
> - --
> Hendrik Maryns
thanks!
Norman D. - 07 Aug 2006 13:58 GMT
I didn't realize 'read' was a colour ;-)
--Norman
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 44 lines]
> =f5BK
> -----END PGP SIGNATURE-----
Luke Webber - 08 Aug 2006 02:19 GMT
> I didn't realize 'read' was a colour ;-)
Certainly it is...
Q: What's black and white and read all over?
A: A newspaper.
Luke
Norman D. - 08 Aug 2006 13:19 GMT
I stand corrected!
--Norman
> > I didn't realize 'read' was a colour ;-)
>
[quoted text clipped - 5 lines]
>
> Luke
Gordon Beaton - 07 Aug 2006 10:08 GMT
> ok, but the object is not null, because until it does not find the null
> line returns the right string.
[quoted text clipped - 14 lines]
> getTag is a method for delete some characters from the string. getValue
> is for extract the text that I want.
In addition to the String comparison issue, the posted example fails
to actually read from the file, so you will never find what you are
looking for.
In order to read the file one like at a time, the loop should look
like this:
while ((line = in.readLine()) != null) {
// process line
...
}
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Oliver Wong - 07 Aug 2006 20:03 GMT
>> equals() is the right method, but you'll have to do a not-null check
>> first, to see whether the object you're invoking it on is not null.
[quoted text clipped - 12 lines]
> while (line != null)
> String readed = getTag(line);
The program will loop forever at this point, because line will never be
null.
[rest of program snipped]
- Oliver