This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reading file with methods  RSS feed

 
Johnny Januan
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm trying to read a file, convert it into a String and then convert it into char [], to parse it and pull words from it.

I wrote this method that reads a file and converts all its content into a String:



One problem that I have is when I call the return value of leerFichero() that is "texto", because it says it can't find it. How do I call a return value from another method??

The second problem will be that when I'm able to call it, how do I read from it just from one part to another. I mean, imagine that this is the file I want to read:

0001 #n word word word #d word word word
0002 #n word word word #d word word word
.......

how do I read from '0' to '#', save that into in a char [], then from 'n' to '#' and save it in a char [] and the same from 'd' to '\n' ???

Thanks
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by " call the return value"? That doesn't make sense to me. You can call a method, not a value or object. How are you calling the leerFichero method? you should be saving the string it returns in some variable...something like:



then you can call a method of your mySavedString as such:



or pass that into another method:



 
Johnny Januan
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code:



Assuming that "StringIPassIn" is the return value of method leerFichero(), what am I doing wrong?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!