I'm trying to remove the : from a text file in notepad, and print it out in the console. I have read the javadocs on strings, but I think I am confused somewhere about the splitter, or how to implement it.
See what I did there? You are splitting myAnimalString into its parts but in line 9 you never use the parts. Instead you still print out the whole myAnimalString.
Also, when using printf(), use %n to output a newline instead of \n
Thanks for the nudge in the right direction without giving it away. I do like to figure these things out on my own, but sometimes you just get stuck on something super simple. Glad I had it mostly right.
Took me a minute to think that out, and after I did there was still a problem, but... I got it.
I am not convinced this question is quite closed.
For one thing, you are not closing your Scanner. You must always close Scanners reading files, sockets, etc. You need not close a Scanner reading a String directly, and you shouldn't close a Scanner reading System.in. Because you need to close the Scanner, it is better to make it a local variable rather than a field. If you look in the Java™ Tutorials, you will find that line 3 will definitely close the file without my writing close(); anywhere.Line 8 depends on the structure of your file and will throw exceptions, or omit data, if you don't have the right number of tokens.
Junilu: your turn. Explain what I have done wrong writing that method and show how it should be refactored.
I marked the thread resolved because OP's main problem has been addressed. However, since you pointed out some things and offered up some code for refactoring, well, I'm your huckleberry.
The first thing that jumps out at me is that the input source (Scanner) and the process (splitting and printing) are tightly bound together. This makes testing difficult. It would be much easier to test the processing logic if it were decoupled from the input source. So, I'd look into using Files.lines() to get a Stream<String> and keep that logic separate from the parsing and printing. I might even separate the parsing and printing logic as well.
I'll leave it to the interested to try to code that out the way I described it. Or even refactor the code given so that it becomes what I described.