FTPから非常に大きなファイルを読み取り、Javaを使用してローカルマシンに書き込むコードを開発しました。それを行うコードは次のとおりです。これはnext(Text key, Text value)
内側からの部分RecordReader
ですCustomInputFormat
if(!processed)
{
System.out.println("in processed");
in = fs.open(file);
processed=true;
}
while(bytesRead <= fileSize) {
byte buf[] = new byte[1024];
try {
in.read(buf);
in.skip(1024);
bytesRead+=1024;
long diff = fileSize-bytesRead;
if(diff<1024)
{
break;
}
value.set(buf, 0, 1024); // This is where the value of the record is set and it goes to the mapper .
}
catch(Exception e)
{
e.printStackTrace();
}
}
if(diff<1024)
{
int difference= (int) (fileSize-bytesRead);
byte buf[] = new byte[difference];
in.read(buf);
bytesRead+=difference;
}
System.out.println("closing stream");
in.close();
書き込みが終了すると、転送が完了し、宛先のファイルのサイズがソースのファイルのサイズと同じであることがわかります。しかし、私はファイルを開くことができず、エディターは次のようにエラーを出します
gedit has not been able to detect the character coding.
Please check that you are not trying to open a binary file.
Select a character coding from the menu and try again.
この質問:JakartaFtpWrapperを使用したJavaアップロードjpg-ファイルを判読不能にするのは、私が信じている私のものに関連していますが、私はそれを理解できませんでした。
ポインタはありますか?