Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

two simple questions on I/O  RSS feed

 
Serena Chen
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hihi! in Java, if I want to read a string like "<id>123</id><place>LA</place>" and I use
BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
input = in.readLine();
I got error: "< was unexpected at this time."
why? and how should I make it be able to read "<"?
2)if I want to keep reading in each character instread of read a line at a time, how should I do it? ie, let's say I have this:
"the first string
the second string
the third string"
if I want the program to read in all 3 lines, not only the first line, how should I do this in Java? (when I use readline(), it only reads in the first line)
Thanks!!!
 
tabi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salam,
ur first mistake is that u don't initilize ur string whom u r assigning ur readed string then u try to use name of stream other then "in" for example use "br" etc
ur second question is that how u read different lines or lines more than one for this u should provide location of that character from which u want to read n to which u want. for coding see books of java u have
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"tabi",
You have already been asked to changes your display name to comply with the naming standard.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Also, please limit the use of contractions 'u', 'ur', 'n' etc. They reduce understanding and we have enough problems with the multipls languages spoken by our visitors.
Thanks.
Dave
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!