File Output/Input

3 posts / 0 new
Last post
wardb5
File Output/Input

I have a couple of problems relating to the use of files as required by the Cypher2 and Decyphering tutorials. My first problem is to do with outputting to a file. Instead of getting a file with 2 seperate lines of text i.e. the jumbled word and the line containing the indexes, I get just one line of text with the jumbled word followed immediately by the indexes. This is despite using println. My output looks as it should when I use the console for instance.

My second problem is relates to inputting from a file. I manually adjusted the file outputted as described above to look as it should and then tried to input it to my decyphering programme. This resulted in an error. I've manually inputted the strings using the console and my programme seems to work ok. I suspect it could be some sort of reverse of the outputing issue I'm encountering.

As everything seems to work fine using the console I think my problems stem from the use of files rather than the actual programme logic. If anyone has any thoughts on the above it'd be most appreciated.

sullivc2
Re: File Output/Input

In response to your first problem use the new line character "\n" to specify that you want the next part of text on a new line.

 

eg. println="first line" +"\n"+ "second line"

will print

first line

second line

feehanl2
Your decypher problem could

Your decypher problem could be something to do with the program you are using to view / edit the outputted text file. Some editors handle the hidden newline character differently. Try creating or re-saving the txt file with just notepad.

Other that that post your program code, otherwise its hard to say whats going wrong.

Login to post comments