File Write
public class FileWrite {
public static void main(String[] args) throws FileNotFoundException, IOException {
FileOutputStream fout=new FileOutputStream("D://file2.txt");
String[] values={"aa","bb","cc"};
PrintWriter pr=new PrintWriter(fout);
for(String value:values){
pr.println(value);
pr.flush();
}
System.out.println("Contents written to file2.txt successfully..!!");
FileInputStream fin=new FileInputStream("D://file2.txt");
BufferedReader br=new BufferedReader(new InputStreamReader(fin));
String content=br.readLine();
System.out.println("Contents of file2.txt are:");
while(content!=null){
System.out.println(content);
content=br.readLine();
}
}
public class FileWrite {
public static void main(String[] args) throws FileNotFoundException, IOException {
FileOutputStream fout=new FileOutputStream("D://file2.txt");
String[] values={"aa","bb","cc"};
PrintWriter pr=new PrintWriter(fout);
for(String value:values){
pr.println(value);
pr.flush();
}
System.out.println("Contents written to file2.txt successfully..!!");
FileInputStream fin=new FileInputStream("D://file2.txt");
BufferedReader br=new BufferedReader(new InputStreamReader(fin));
String content=br.readLine();
System.out.println("Contents of file2.txt are:");
while(content!=null){
System.out.println(content);
content=br.readLine();
}
}
}
Output:Contents written to file2.txt successfully..!!
Contents of file2.txt are:
aa
bb
cc