Chapter 5 Example
Chapter 5 Example
package bwritestext;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
// try {
out.write("**************************************");
out.newLine();
out.write("------------------------------------");
out.newLine();
out.newLine();
out.newLine();
out.newLine();
out.write("*************************************");
out.close();
//catch (IOException e) {
//System.out.println(e.getMessage());
//}
Output
File created successfully
BUILD SUCCESSFUL (total time: 0 seconds)
import java.io.*;
String str;
while((str=in.readLine())!=null){
System.out.println(str);
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
try {
if(!file.exists()){
file.createNewFile();}
bw.write(newcontent);
bw.write(add);
bw.close();
String str;
br.close();
catch(IOException e) {
output
data successfully Append
exception occouredjava.io.FileNotFoundException: E:\Test3.txt (The device is
not ready)
BUILD SUCCESSFUL (total time: 0 seconds
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
String str;
while((str=in.readLine())!=null){
bw.write(str);
in.close();
bw.close();
System.out.println("copied successfully");
Output
copied successfully
BUILD SUCCESSFUL (total time: 0 seconds)
import java.io.File;
try{
if(f.exists()){
f.delete();
else{
catch(Exception e){
System.out.println(e.getMessage());
import java.io.File;
if(!file.exists()){
System.out.println("not fund");
return file.length();
System.out.println(size);