ファイル操作
テキスト処理
import java.io.*;
class sample12{
public static void main
(String[] args
){
try{
// ファイル書き込み
pw.println("aaaaaaaaaaaaaaaa");
pw.println("bbbbbbbbbbbbbbb");
pw.println("ccccccccccccc");
pw.close();
// ファイル読み込み
while((line = br.readLine()) != null){
}
br.close();
fw.close();
fr.close();
ex.printStackTrace();
}finally{
}
}
}
バイナリ処理
import java.io.*;
class sample13{
public static void main
(String[] args
){
try{
// バイナリ書き込み
byte[] b1 = "aaaaaaaaaaa".getBytes();
byte[] b2 = "bbbbb".getBytes();
byte[] b3 = "cccccccccccccccc".getBytes();
fos.write(b1);
fos.write(b2);
fos.write(b3);
fos.close();
// バイナリ読み込み
byte[] c = new byte[10];
int length = 0;
while((length = fis.read(c, 0, c.length)) != -1){
baos.write(c, 0, length);
}
byte[] d = baos.toByteArray();
fis.close();
ex.printStackTrace();
}finally{
}
}
}
最終更新:2012年09月02日 10:19