This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Write into a file in a Map format  RSS feed

 
Nitasha Gupta
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write into the file in a Map format, like

Key Value
t1 hello
t2 hi

How can I write into a File in this format???
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this:

out.println("t1\thello");
out.println("t2\thi");

But there's probably more to your question than that...
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15861
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no ready made method that does this for you. You'll have to open a text file yourself, loop through the entries in the map and write a line with the key, a space, and the value for each entry in the map. It's not so difficult to write this.

Use class java.io.FileWriter to write to a text file. Use Map.entrySet().iterator() to get an Iterator which you can use to loop over the entries in the map.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!