// Text file using BufferedOutputStream
import java.io.*;
class CreateFileDemo
{
public static void main(String[]arr)
throws IOException{
// attch keybord to DataInputStream
DataInputStream dis=new DataInputStream(System.in);
// attch myfile to fileOutputStream in append mode.
FileOutputStream fout =new FileOutputStream("myfile.txt",true);
// attch FileOutputStream to BufferedOutputStream
BufferedOutputStream bout=new BufferedOutputStream(fout,1024);
System.out.println("Enter the text (@ at the end):");
char ch;
// read character from dis into ch . Then write them into bout .
// repeat this as long as the read Character is not @
while((ch=(char)dis.read()) !='@')
bout.write(ch);
//close the file
bout.close();
}
}
That is Output
E:\ShashiJava>javac CreateFileDemo.java
E:\ShashiJava>java CreateFileDemo
Enter text (0 to the end)
Hello I am Shahsi This File No Is One
Hello I am Shahi This File No Is Two
@
E:\ShashiJava>myfile.txt
E:ShashiJava>
This is my file line one
This is my file line two Hello I am Shahsi This File No Is One
Hello I am Shahi This File No Is Two
0 comments:
Post a Comment