considering the following function
private static void GetText(String nodeValue) throws IOException {
if(!file3.exists()) {
file3.createNewFile();
}
FileOutputStream fop=new FileOutputStream(file3,true);
if(nodeValue!=null)
fop.write(nodeValue.getBytes());
fop.flush();
fop.close();
}
what to add to make it to write each time in the next line?
for example i want each words of a given string in a seperate lline for example:
i am mostafa
writes as:
i
am
mostafa
To write text (rather than raw bytes) to a file you should consider using FileWriter. You should also wrap it in a BufferedWriter which will then give you the newLine method.
To write each word on a new line, use String.split to break your text into an array of words.
So here’s a simple test of your requirement:
The output is: