【发布时间】:2017-10-20 04:36:23
【问题描述】:
在将读取的文件打印到新文件时遇到问题。下面是财务文件中的示例数据:
资本
2215.281234
韦弗,艾迪生大学
902-6238 Purus, Avenue
兴趣
22343.623428
弗罗斯特,塔娜 Y。
邮政信箱埃尼姆路 3494 号 902 号信箱
当我运行它时,我得到的只是:
姓名:
地址:
等等
因此,在“名称”或“地址”之后,它不会显示相应的名称或为该税码添加。但是,它读取文件写入;它没有在屏幕或文件中打印名称和地址的问题。如果有人可以帮助我,将不胜感激。印刷是我唯一遇到的问题。提前致谢。
package fh;
import java.util.Scanner; import java.io.*;
public class fh { public static void main(String [] args) throws IOException
{
String taxcode ,name , address;
double tax = 0, income = 0;
String financeAdd = "C:\\Users\\name\\workspace\\finance.txt";
String correctRec = "C:\\Users\\name\\workspace\\taxrecords.txt";
String wrongRec = "C:\\Users\\name\\workspace\\recorderror.txt";
File file = new File(financeAdd);
Scanner s = new Scanner(file);
PrintWriter outfile = new PrintWriter(correctRec);
PrintWriter outfile2 = new PrintWriter(wrongRec);
while(s.hasNext())
{
taxcode = s.nextLine();
switch (taxcode)
{
case "Dividend":
income = Double.parseDouble(s.nextLine());
name = s.nextLine();
address = s.nextLine();
tax = (income * 1.25 - (income * 1.25 * 0.33)) * 0.22;
outfile.printf("%s%n%s%n","Name: ","Address: ", name, address);
System.out.printf("%s\n%s\n","Name: ","Address: ", name, address);
break;
case "Interest":
income = Double.parseDouble(s.nextLine());
name = s.nextLine();
address = s.nextLine();
tax = income * 0.22;
outfile.printf("%s%n%s%n","Name: ","Address: ", name, address);
System.out.printf("%s\n%s\n","Name: ","Address: ", name, address);
break;
case "Capital":
income = Double.parseDouble(s.nextLine());
name = s.nextLine();
address = s.nextLine();
tax = income * 0.50 * 0.22;
outfile.printf("%s%n%s%n","Name: ","Address: ", name, address);
System.out.printf("%s\n%s\n","Name: ","Address: ", name, address);
break;
default:
income = Double.parseDouble(s.nextLine());
name = s.nextLine();
address = s.nextLine();
outfile2.printf("%s%n%s%n","Name: ","Address: ", name, address);
System.out.printf("%s\n%s\n","Name: ","Address: ", name, address);
break;
}
}
System.out.println("Data Processed");
s.close();
outfile.flush();
outfile.close();
outfile2.flush();
outfile2.close();
}
}
【问题讨论】:
标签: java io printwriter