1.
package Si;
import java.io.*;
public class Text {
public static void main(String[] args) {
// InputStream is=null;
Writer fw = null;
BufferedWriter w = null;
String data = null;
try {
fw = new FileWriter("C:\\class.txt");
w = new BufferedWriter(fw);
w.write("66666666");
//while (data != null) {
//System.out.println(data);
//data = r.readLine();
//}
} catch (FileNotFoundException e) {
System.out.println("error");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("error");
e.printStackTrace();
} finally {
try {
w.close();
} catch (IOException e) {
System.out.println("error");
e.printStackTrace();
}
}
}
}
2.
import java.io.*;
public class Text {
public static void main(String[] args) {
// InputStream is=null;
Reader fr = null;
BufferedReader r = null;
String data = null;
try {
fr = new FileReader("C:\\class.txt");
r = new BufferedReader(fr);
data = r.readLine();
while (data != null) {
System.out.println(data);
data = r.readLine();
}
} catch (FileNotFoundException e) {
System.out.println("error");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("error");
e.printStackTrace();
} finally {
try {
fr.close();
} catch (IOException e) {
System.out.println("error");
e.printStackTrace();
}
}
}
}