Import java.io.*;
public class Example {
static final int linelength = 81;
public static void Main (string[] args) {
FileOutputStream Fos;
byte[] phone = new Byte[linelength];
byte[] name = new Byte[linelength];
try {
FOS = new FileOutputStream ("Word.txt");
while (true) {
System.err.println ("Please enter a name:");
if ("Done". Equalsignorecase (New String (name, 0, 0, 4))) {
SYSTEM.OUT.PRINTLN ("entry Complete");
Break
}
System.err.println ("Please enter phone number:");
ReadLine (phone);
for (int i = 0; phone[i]! = 0; i++) {
Fos.write (Phone[i]);
}
Fos.write (', ');
for (int j = 0; name[j]! = 0; j + +) {
Fos.write (Name[j]);
}
Fos.write (' \ n ');
SYSTEM.OUT.PRINTLN ("The information has been written to the file");
}
Fos.close ();
} catch (Exception e) {
TODO automatically generates catch blocks
E.printstacktrace ();
}
}
private static void ReadLine (byte[] name) throws IOException {
int b = 0, i = 0;
while ((I < (lineLength-1)) && (b = System.in.read ()) = = ' \ n ') {
name[i++] = (byte) b;
}
Name[i] = (byte) 0;
}
}
JAVA_I/O Input and output _ implementation when the user enters a name and password, each name and password is added to the file, and if the user enters done, the program ends.