by
149 11
1
6
3,277
3
Top 1% !
Popular
Famous
Easy-to-find
Specified
OpenSource
Popularity: 3363rd place
Created
Modified Jul 28, 2014
Languagejava
LicenseMIT_X11

Read/Write File in Java

An easy way to read a file and append text to it
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/98794/Read-Write-File-in-Java?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
try { File aFile = new File("/Path/to/File/file_name.txt"); //Set parameter true if you want to append content otherwise false BufferedWriter bW = new BufferedWriter(new FileWriter(aFile,true)); String line = "Text to file"; bW.write(line); bW.newLine(); bW.flush(); bW.close(); } catch (IOException e) { //Put catching code here }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus