import java.io.*;
class CreateFile
{
public static void main(String[]arr)
throws IOException
{
// attech keyword to DataInputStream
DataInputStream dis=new DataInputStream(System.in);
// attch my file to fileOutput Stream
FileOutputStream fos=new FileOutputStream("myfile.txt");
System.out.println("Enter text (0 to the end )");
char ch;
// read charachters from dis into ch. Then write them into fouut.
// repeat this as long as the read Character is not @
while ((ch=(char)dis.read())!='@')
fos.write(ch);
// close the file
fos.close();
}
}
That is Output
E:\ShashiJava>javac CreateFile.java
E:\ShashiJava>java CreateFile
Enter text (0 to the end)
This is my file line one
This is my file line two
@
E:\ShashiJava>myfile.txt
E:ShashiJava>
This is my file line one
This is my file line two
class CreateFile
{
public static void main(String[]arr)
throws IOException
{
// attech keyword to DataInputStream
DataInputStream dis=new DataInputStream(System.in);
// attch my file to fileOutput Stream
FileOutputStream fos=new FileOutputStream("myfile.txt");
System.out.println("Enter text (0 to the end )");
char ch;
// read charachters from dis into ch. Then write them into fouut.
// repeat this as long as the read Character is not @
while ((ch=(char)dis.read())!='@')
fos.write(ch);
// close the file
fos.close();
}
}
That is Output
E:\ShashiJava>javac CreateFile.java
E:\ShashiJava>java CreateFile
Enter text (0 to the end)
This is my file line one
This is my file line two
@
E:\ShashiJava>myfile.txt
E:ShashiJava>
This is my file line one
This is my file line two
0 comments:
Post a Comment