This site requires JavaScript, please enable it in your browser!
Greenfoot back
GreenAnthony
GreenAnthony wrote ...

2014/1/21

How to create files...?

GreenAnthony GreenAnthony

2014/1/21

#
Hey everybody, I already know like all those main codes but lately I just wanted to learn a few more detailed and stronger codes so since Greenfoot is using Java as a language I googled how to create files in Java and it gave me this:
PrintWriter writer = new PrintWriter("New-File.txt", "UTF-8");
writer.println("The first line");
writer.println("The second line");
writer.close();
it is supposed to make a .txt file but Greenfoot tells me it doesn't know the command PrintWriter (or it at least shows me there is an error) so why doesn't it work? How to fix it? Is there a way of making new files using Greenfoot? Cuz I dont know how to use Eclipse yet... If yes how?
lordhershey lordhershey

2014/1/21

#
check this little example: http://www.justexample.com/wp/write-file-with-printwriter/ you might just be missing the import java.io.* line
You need to login to post a reply.