java.io.*;
import
java.util.*;
public
class gwxt
{
private String adm, pas;
publicvoid in()
{
Scanner in =
new Scanner(System.in);
System.
out.println("\n" + "請輸入用戶名:");
adm = in.next();
System.
out.println("\n" + "請輸入密碼:");
pas = in.next();
//沒有針對用戶名,密碼錯誤進行反復操作,'重新輸入'無效
if (adm.equals("admin") && pas.equals("password"))
{
System.
out.println("歡迎登錄!");
readFileByLines(
"c:/java/gwxt/Main.txt");
}
else
{
System.
out.println("輸入有誤,請重新輸入!");
}
}
publicstaticvoid readFileByLines(String fileName) {
File file =
new File(fileName);
BufferedReader reader =
null;
try {
System.
out.println("購物系統 -- 客戶信息管理" + "\r\n"
+
"--------------------------------------");
reader =
new BufferedReader(new FileReader(file));
String tempString =
null;
int line = 1;
// 壹次讀入壹行,直到讀入null為文件結束
while ((tempString = reader.readLine()) != null) {
// 顯示行號
//行號直接用數字顯示就可以了,用數組畫蛇添足
// int[] count = new int[line];
//
// for (int i = 0; i < line; i++)
//
// {
//
// count[i] = line;
//
// }
System.
out.println(line + ". " + tempString);
line++;
}
System.
out.println("--------------------------------------");
reader.close();
//多余,交給finally處理
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if (reader != null) {
try {
reader.close();
}
catch (IOException e1) {
}
}
}
}
publicstaticvoid main(String[] args)
{
new gwxt().in();
}
}