/* WriteFile.java
Receive keyboard input and output to screen as-is
In addition, the data entered by the keyboard is stored sequentially in the file
How to use: Java WriteFile file name
To end this program, enter a # number at the beginning of the row.
*/
Import java.io.*;
Class WriteFile
public class WriteFile
{
public static void Main (string[] args)
{
byte[] buff = new byte[1024];
Boolean cont = TRUE; loop control variable
FileOutputStream outfile = null; File Output objects
Generate object outfile, prepare to output to file
Try
{
outfile = new FileOutputStream (args[0]);
}
catch (FileNotFoundException e)
{
SYSTEM.ERR.PRINTLN ("File does not exist");
System.exit (1);
}
The following loop is performed when the beginning of the line does not enter a period
while (cont)
{
Try
{
int n = System.in.read (buff); Reading data from system.in
System.out.write (buff, 0, N); Write to System.out
if (Buff[0]==´#´)
{
Cont = FALSE;
}
Else
{
Outfile.write (buff, 0, N);
}
}
catch (Exception e)
{
System.exit (1);
}
}
Close File
Try
{
Outfile.close ();
}
catch (IOException E)
{
SYSTEM.ERR.PRINTLN ("File Error");
System.exit (1);
}
}
}