package com.as400samplecode;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class FileBufferedWriter {
public static void main(String[] args) {
BufferedWriter bufferedWriter = null;
try {
File file = new File("data/newFile.txt");
//to append more data to the existing file change the line to
//File file = new File("data/newFile.txt",true);
//if file doesn't exists, then create it
if(!file.exists()){
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write("My first line!");
bufferedWriter.newLine();
bufferedWriter.write("My second line ");
bufferedWriter.write("keeps going on...");
bufferedWriter.newLine();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bufferedWriter != null){
bufferedWriter.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
Blog Archive
-
▼
2012
(275)
-
▼
May
(55)
- How to fix Debug Certificate expired Android Error...
- Android Button Click example
- Sencha Touch 2 List with Load More option - Ext.pl...
- Sencha Touch 2 List example with buttons such as A...
- Sencha Touch 2 List disclosure icon example
- Sencha Touch 2 List with IndexBar example
- Sencha Touch 2 grouped list example
- Sencha Touch 2 List itemtap example
- Sencha Touch 2 List examples using Java Servlet an...
- Java convert JSON string to object example using G...
- Java convert object to JSON string example using G...
- jQuery load javascript on demand, basically at run...
- jQuery check if an element exists or not
- jQuery Get input Text value example, and how to se...
- Java write to file using BufferedWriter example
- How to make recursive program calls in RPGLE using...
- RPGLE QCMDEXC example
- Java Read File using BufferedReader example
- Java Read File using BufferedInputStream example
- How to create a file in Java if one doesn't exists...
- Display Project/Directory listings in Tomcat Home ...
- ExtJs loop through Store Records
- Android Replace "..." with ellipsis character
- jQuery STOP user from page exit - window beforeunl...
- jQuery reload HTML page at regular intervals
- ExtJs 4 Card Layout example with Grid Panel and Na...
- ExtJs 4 Card Layout example with Grid Panel and Na...
- ExtJs 4 Card Layout example with Grid Panel and Na...
- How to get the HTML Table cell value using jQuery
- jQuery $(selector).each() example
- jQuery manipulate Table using detach() and append(...
- jQuery get Button value when clicked
- jQuery change HTML Table Row Color on hover
- jQuery shade HTML Table with alternating Row Color...
- Linux Centos Automatically Start Apache Tomcat ser...
- Service does not support chkconfig
- How to check run level for your Linux Mint machine...
- How to solve no soundcards found after installing ...
- Linux Mint change machine name
- DB2 set AUTO_INCREMENT value
- CREATE table SQL auto increment primary key
- MySQL set AUTO_INCREMENT value
- Check if Java is installed on Linux Mint and find ...
- Install Chrome browser on Linux Mint - Chromium
- JQuery Cross Domain Java Servlet AJAX Request with...
- Install VMware Tools on Linux Mint 12
- Install Linux Mint 12 using VMware player on Windo...
- ExtJs update DIV content with HTML data
- JSP find server host name - getServerName()
- Java Tomcat Linux VPS hosting experience and Apac...
- iSeries Java exception java.lang.NoSuchMethodError...
- Rename a field in CL Program - iSeries(AS400)
- Java @override Annotations - What does it mean ?
- Java abstract method and class, What does it mean ...
- Android emulator localhost issue - Can't connect t...
-
▼
May
(55)
Java write to file using BufferedWriter example
BufferedWriter provides efficient method of writing single characters, arrays, and strings. You can specify a buffer size but the default is large enough for most purposes. A newLine() method is provided, which uses the platform's own notion of line separator as defined by the system property line.separator. Not all platforms use the newline character ('\n') to terminate lines. Calling this method to terminate each output line is therefore preferred to writing a newline character directly.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment