📄 phones.java
字号:
package phones;
/**
* Java语言实验参考程序
* Company 北京师范大学计算机系
* @author 孙一林
* @version 1.0
*/
import java.io.*;class Phones { static FileOutputStream fos; public static final int lineLength = 100; public static void main(String args[]) throws IOException { byte[] phone = new byte[lineLength]; // 定义数组变量 byte[] name = new byte[lineLength]; int i; fos = new FileOutputStream( "电话号码.txt" ); // 创建输出文件 while (true) { System.err.println( "请输入姓名:(输入 'exit'则退出)" ); readLine(name); // 读入一行字符 if ( "exit".equalsIgnoreCase(new String(name,0,0,4)) ){ break; } System.err.println( "请输入电话号码:" ); readLine(phone); for ( i = 0; phone[i] != 0; i++ ){ // 写一行字符到文件 fos.write(phone[i]); } fos.write(','); for (i=0;name[i]!= 0;i++){ fos.write(name[i]); } fos.write('\n'); } fos.close(); } private static void readLine(byte line[]) throws IOException { int i=0,b=0; // 读入一行字符函数 while (( i < lineLength - 1 )&&(( b = System.in.read() ) != '\n')) line[i++] = (byte)b; line[i]=(byte) 0; // 加入一行结束符0 }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -