txt ファイルからレコード全体を読み取り、各フィールドを個別に取得し、各フィールドを個別の文字ストリームに変換する方法。次に、個々の文字の文字ストリームを (ループで) プレーン ASCII 出力テキスト ファイルに書き込みます。
私は自分のクラス定義を持っていますが、出力ファイルを適切に書き込むことができないようです。これは、一度に 1 つのプレーン ASCII テキスト文字でなければなりません。少しだけ助けが必要です。これが私がこれまでに持っているものです:
----- これは私の最初の質問です。うまくフォーマットされていない場合は申し訳ありません:(オブジェクトのファイルを「yankees.txt」と呼ばれるプレーンASCII文字テキストファイルに変換しようとしています。個別に各フィールドを個別の文字ストリームに変換し、各フィールドから一度に1文字ずつ文字を「yankees.txt」に書き込みますObjectInputStream
public class yankeesfilemain {
public static void main(String[] args) throws EOFException {
ObjectInputStream is;
OutputStream os;
yankees y;
int i, j, k;
String name, pos;
int number;
File fout;
try {
is = new ObjectInputStream(new
FileInputStream("yankees.yanks"));
y = (yankees)is.readObject();
fout = new File("yankees.txt");
os = new FileOutputStream(fout);
while (y != null) {
name = y.getname();
pos = y.getpos();
number = y.getnum();
for (i = 0; i < .length(); i++) {}
for (j = 0; j < .length(); j++) {
pos = y.getpos();
}
for (k = 0; k < .length(); k++) {
number = y.getnum();
}
break;
}
os.close();
is.close();
} catch(EOFException eof) {
eof.printStackTrace();
System.exit(0);
} catch(NullPointerException npe) {
npe.printStackTrace();
System.exit(0);
} catch(NumberFormatException nfe) {
nfe.printStackTrace();
System.exit(0);
} catch(IOException e) {
e.printStackTrace();
System.exit(0);
}
}
}