private static int count = 0;
public static String[] play()throws Exception{
File file=new File("E:/proj/"+count+".bin");
FileInputStream fin=new FileInputStream("E:/proj/"+count+".bin");
//reading the byte content of the bin files
byte fileContent[] = new byte[(int)file.length()];
fin.read(fileContent);
//storing the deserialized object that is returned to an object.
Object obj=serializer.toObject(fileContent);
//converting the obtained object to string
String word=obj.toString();
String[] args=new String[]{word};
count++;
return args ;
}
このコードは、実際にその指定されたパスに存在するすべてのbinファイルを読み込み、最終的にはそれを文字列に変換し、string[]
リターンですべてのbyte[]
文字列に変換など、さまざまな文字列の要素を格納することになりました。 string[]
。カウンタのためにすべてのbinファイルを読み込んでいますが、何とかして、読み込んだ最初のバイナリファイルの文字列だけを返します。読書と返す複数のbinファイル
この変更されたバージョンの用量でも動作するようです。私はそれがすべてのbinファイルを読むと思うが、読み込まれた最後のbinファイルの文字列だけを返す。私が試していたのは、すべての文字列要素をstring[]
に格納し、別の呼び出し関数にstring[]
を返すことでした。
public static String[] play(){
int i = 1;
String[] args=null;;
String result = null;
while (true) {
try {
result += processFile(i++);
args=new String[]{result};
}
catch (Exception e) {
System.out.println("No more files");
break;
}
}
return args;
}
private static String processFile(int fileNumber) throws Exception {
File file=new File("E:/proj/"+fileNumber+".bin");
FileInputStream fin=new FileInputStream("E:/proj/"+fileNumber+".bin");
//reading the byte content of the bin files
byte fileContent[] = new byte[(int)file.length()];
fin.read(fileContent);
//storing the deserialized object that is returned, to an object.
Object obj=serializer.toObject(fileContent);
//converting the obtained object to string
String word=obj.toString();
return word;
}
ループ内からplay()メソッドが呼び出されていますか?残りのコードを表示できますか? – assylias
hii Assylias...再生メソッドはループ内から呼び出されません。それは単に別のクラスで呼ばれているだけです... – kuki