Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
why not write in file
david luis
Ranch Hand
Posts: 69
1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi. I have these code to write in a tmp file but I see the file wihout data. Could you help me please?
Thanks and sorry for my English!
if (arg0.getActionCommand().contentEquals("Aplicar Conexion")){ System.out.println("Boton Aplicar Cambios"); String tempDir = System.getProperty("java.io.tmpdir"); File tempFile = new File(new File(tempDir), "userDetail.tmp"); tempFile.canWrite(); PrintWriter pw = null; if(tempFile.exists()){//This is subsequent login tempFile.delete(); try { pw = new PrintWriter(tempFile); pw.println(userText.getText()); pw.println(passwordText.getText()); pw.println(hostText.getText()); pw.println(hostSID.getText()); pw.println("sjldfkasdfjkl"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Write your code to read file and //your application logic }else{ //This is first login try { pw = new PrintWriter(tempFile); pw.println("linea es ..." + userText.getText()); pw.println(passwordText.getText()); pw.println(hostText.getText()); pw.println(hostSID.getText()); pw.println("sjldfkasdfjkl"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Write your logic to write data to the file } ;
Ulf Dittmer
Rancher
Posts: 43081
77
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You need to close Streams and Writers when you're done with them.
Also, line 6 is wrong - you need to check the return value and act accordingly.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Big Integer to String - weird characters
exception handling
Printwriter
How do i write a XML file using Java?
how to write into a property file from web browser
More...