473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Writing to files in java

In this program I have everything running perfectly but in the addRecord() function I need to add more information. But I am not able to print it on a new line.
Everything is displaying in the same line.

Can someone point me out on that.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.lang.*;
  3. import java.util.*;
  4. public class createfile {
  5.     public static void main(String args[]){
  6.  
  7.         createfile obj= new createfile();
  8.         obj.openfile();
  9.         obj.addRecords();
  10.         obj.closefile();
  11.         System.out.println("You have created a file");
  12.  
  13.     }
  14.     private Formatter x;
  15.     public void openfile(){
  16.  
  17.         try{
  18.             x = new Formatter("C:\\test\\chinese.txt");
  19.         }
  20.         catch(Exception e){
  21.             System.out.println("You have an error");
  22.         }
  23.     }
  24.  
  25.     public void addRecords(){
  26.         x.format("%s %s %s","21","alex","software programmer");
  27.         x.format("%s %s %s", "22","greg", "architecture");
  28.     }
  29.     public void closefile(){
  30.         x.close();
  31.     }
  32. }

Thank You..
Jan 9 '15 #1
1 1336
Frinavale
9,735 Expert Mod 8TB
To print a "new line" in java you need to use the escape code: \n.

Check out this documentation on Characters but especially the section on Escape Sequences.

-Frinny
Jan 12 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Lucas Raab | last post by:
What is the best way to go about writing to files?? Whenever I insert a statement to write results to a file there's nothing in it. Any suggestions?? TIA
5
by: Ben Jeurissen | last post by:
Hello, I have to deal with the following issue in C++: Two threads are started from the main thread, both capturing images from a different firewire camera. Both threads take shots of 460800...
3
by: Adonis Vargas | last post by:
I am writing a program that walks a directory full of mp3s reads their ID3 data (using Mutagen), this part works perfectly. The problem is I write these tags to a CSV file through the CSV module....
19
by: r035198x | last post by:
The program below simply reads a file called FileTest1.java(itself) and prints it to the console import java.util.Scanner; import java.io.*; class FileTest1 { public static void...
2
by: toprahman | last post by:
Hi guys, I'm a student teacher at a high school in Washington D.C. and I've come across a slight problem. See, I'm a math major, but one of the computer science teachers just quit and they need me to...
5
by: RyanL | last post by:
I'm a newbie with a large number of data files in multiple directories. I want to uncompress, read, and copy the contents of each file into one master data file. The code below seems to be doing...
3
by: aaljumah | last post by:
i am naive with java programming. I would like create a program to read a set of text files, analyze them and create an output in an xml format or at least to another one txt file. here is how...
3
by: pradeepavelu | last post by:
Friends, I would like to know about what are the standards(Rules) or conventions that are to be followed while writing a JAVA or J2EE code.
16
by: AAaron123 | last post by:
I have a timer. At each tick, say 0.1 second, I write a file. If it takes more than 0.1 second to write the file the app will not work correctly. How can I tell in the tick event if the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.