issue with FileReader and FileWriter
hi all,
please help me here
I am getting a unwanted answered to write and read to file .
Below is the code of it
The size of array is coming as -1 and hence if retrieve values from the array also, it is displaying null.
package chap6;
import java.io.*;
public class Chap61 {
public Chap61() {
}
public static void main(String[] args) {
try {
// char [] n = new char[50];
int size = 0;
boolean newFile = false;
File file = new File("testFile.doc");
System.out.println("file exists:" + file.exists());
file.createNewFile();
//below is to wrap the file with FileWriter
BufferedWriter bw= new BufferedWriter(file);
bw.write("uma");
// FileWriter nf = new FileWriter(file);
// nf.write("first");
System.out.println("new fiel created" + newFile);
System.out.println("file exists:" + file.exists());
//below is to wrap the file with FileWriter
// FileReader fr = new FileReader(file);
BufferedReader br= new BufferedReader();
size=br.read(n);
//size = fr.read(n);
System.out.println("new file size is :" + size);
for (char c: n) {
System.out.print("characters are :" + c + "\n");
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
result of the array is :
new file size is :-1
Please let me know where I am going wrong
Thanks
Uma