Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
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
Ron McLeod
Paul Clapham
Tim Cooke
Devaka Cooray
Sheriffs:
Liutauras Vilda
paul wheaton
Rob Spoor
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Piet Souris
Mikalai Zaikin
Bartenders:
Carey Brown
Roland Mueller
Forum:
Beginning Java
how to write the String Array into the new file
niras iva
Greenhorn
Posts: 18
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello Sir:
i create a own file My coding is here,
try { File file = new File("Logfile.txt"); fos = new FileOutputStream(file); dos=new DataOutputStream(fos); } catch (IOException e) { System.out.println(e); }
i want to write the value of s in my file.
for(String s : WMSLoggerIDs.FD_ALL) { System.out.println(s+": publish "+WMSLoggerFactory.getGlobalLogValue(s)); }
i want to take the value of s and write into my new file..how can i do this?
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you want to write it as text, then don't use DataOutputStream. Streams (InputStream and OutputStream) are for reading and writing binary data, not text. If you want to write text, use a Writer instead of an OutputStream. For example:
String[] array = ... // wherever you get this from; File file = new File("Logfile.txt"); PrintWriter out = new PrintWriter(new FileWriter(file)); // Write each string in the array on a separate line for (String s : array) { out.println(s); } out.close();
Jesper's Blog
-
Pluralsight Author Page
niras iva
Greenhorn
Posts: 18
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you sir
Hey! Wanna see my flashlight? It looks like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
DataOutputstream writeshort doesnt work
problem with writing file , please help
Creating Excel File - POI
write problem in text file
Problem in writing any double in a file
More...