我开发了一个代码,它从 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.
这个问题:Java upload jpg using JakartaFtpWrapper -使文件不可读我相信与我的有关,但我无法理解。
任何指针?