日期:2014-05-20 浏览次数:20881 次
package worktwo;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Bank {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
File src = new File("F:\\test.txt");
if (!src.exists()) {
src.createNewFile();
} else
System.out.println("logn right");
System.out.println("1-存钱 2-取钱 3-查询余额 4-退出");
FileReader fr = new FileReader(src);
BufferedReader br = new BufferedReader(fr);
String num = br.readLine();
br.close();
int count;
if (num == null)
count = 0;
else
count = Integer.parseInt(num);
FileWriter fw = new FileWriter(src, false);
BufferedWriter bw = new BufferedWriter(fw);
// 读出文件中的数字给count
int a = s.nextInt();// 进行操作选择
while (true) {
switch (a) {
case 1:// 存操作
System.out.println("存钱number");
int a1 = s.nextInt();
count = count + a1;
num = String.valueOf(count);
bw.write(num);
bw.flush();
break;
case 2:// 取操作
System.out.println("取钱 number");
int a2 = s.nextInt();
if (a2 > count)
System.out.print("清输入正确的取款数");
else
count = count - a2;
bw.write(num);
bw.flush();
break;
case 3:// 显示TXT中的数字
System.out.println(count);
num = String.valueOf(count);
bw.write(num);
break;
case 4:// 退出
bw.close();
return;
default:
bw.close();
System.out.print("清输入正确的选项");
break;
}
}
}
}
package com.kiritor;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Bank {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
File src = new File("F:\\test.txt");
if (!src.exists()) {
src.createNewFile();
} else
System.out.println("logn right");