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.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.