新しいファイルに読み込んだファイルを印刷する際に問題が発生しました。そこでここでは金融ファイルからのサンプルデータがあります:ファイルを読み込みますが、新しいファイルに送信すると正しく印刷されませんか?
資本
2215.281234
ウィーバー、アディソンU.
902から6238プルス、アベニュー
インタレスト
22343.623428
フロスト、タナY.
P.O.ボックス902、3494 Enim道路
私はそれを実行したとき、私はなっていたすべては次のようになります。
名:
住所:
など
だから、 "名前" の後にまたは "住所"の場合、それぞれの名前またはその税コードの追加は表示されません。ただし、ファイルの書き込みは読み取ります。問題は、画面上またはファイル内に名前と住所を表示しないことです。誰かが私にこれを手伝ってもらえると大変感謝しています。私が持っている唯一の問題は印刷です。前もって感謝します。
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();
}
}
ありがとうございました!私はちょっと微調整しなければならなくて、今働いています。私はこのようなコードをフォーマットしていましたが、これが初めての問題です。 –