phones.java

来自「介绍有关java的资料 课件 相当一本书籍 里面都是很基础的知识」· Java 代码 · 共 39 行

JAVA
39
字号
		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;
			}
		}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?