how to write an output in 2nd line
package readtext;
import java.io.*;// For input & output classes
import java.util.Date;// For the Date class
public class input {
public input() {
}
public static void main(String[] args)
{
try
{
String dirName = "C:/Documents and Settings/seng/Desktop/testfile"; // Directory for the output file
String fileName = "data.txt"; // Name of the output file
File output = new File(dirName, fileName);
output.createNewFile();// Create a new file if necessary
if(!output.isFile())// Verify we have a file
{
System.out.println("Creating " + output.getPath() + " failed.");
return;
}
BufferedWriter out = new BufferedWriter(
new FileWriter(output.getPath(), true));
BufferedReader in = new BufferedReader(
new FileReader("C:/Documents and Settings/seng/Desktop/testfile/txt.txt"));
String text;
while ((text = in.readLine()) != null)
{
for (int i = 0; i < text.length(); i++) //print whole sentance
{
char word = text.charAt(i);
out.write(word);
out.flush();
}
}
out.close();
}
catch(IOException e)
{
System.out.println("Error writing the file " + e);
}
}
}
currently i have a set of data which contain of 3 line
abcdef
ghijkl
123456
by running my program, i only can write the whole data in 1 sentance line, which is like this.
ab cd ef gh ij kl 12 34 56
i have try to change the write() to out.write(word(i) + "\n")...but it dint take any effect...Does any1 know how to solve for the problem?
i wish my data can print out like original:
abcdef
ghijkl
123456

