水曜日, 2月 07, 2007
[Java]ファイル入出力ストリーム関連
public int FileRead( String fname ) {
int ret = 0;
BufferedReader reader = null;
if ( fname == null ) return -1;
try {
reader = new BufferedReader( new FileReader( fname ) );
String line = null;
while ( (line = reader.readLine()) != null ) {
System.out.println( line );
ret++;
}
}
catch ( FileNotFoundException e ) {
System.out.println( "ファイルが見つかりません。" );
ret = -2;
}
catch ( IOException e ) {
System.out.println( "入出力エラーです。" );
ret = -3;
}
finally {
try {
if ( reader != null ) reader.close();
}
catch ( Exception e ) {}
}
return ret;
}
int ret = 0;
BufferedReader reader = null;
if ( fname == null ) return -1;
try {
reader = new BufferedReader( new FileReader( fname ) );
String line = null;
while ( (line = reader.readLine()) != null ) {
System.out.println( line );
ret++;
}
}
catch ( FileNotFoundException e ) {
System.out.println( "ファイルが見つかりません。" );
ret = -2;
}
catch ( IOException e ) {
System.out.println( "入出力エラーです。" );
ret = -3;
}
finally {
try {
if ( reader != null ) reader.close();
}
catch ( Exception e ) {}
}
return ret;
}