i am newbie to hadoop, and trying to upload and download files to hdfs via. Java code. which should behave as
Data Uploading:
hadoop fs -put or -copyFromLocal filename directoryName
and Data Downloading
hadoop fs -get or -copyToLocal filename directoryName
from hdfs. i need this one because datasets contain image, audio, video etc file. above command works fine with all type of data, if i try using Java i/o reader code , it is working fine for text files , but not for images, video. docx etc..
pls any help here.
Edited Here:
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Configuration conf=new Configuration();
FileSystem fs = FileSystem.get(conf);
Path path=new Path("data");
Path file=new Path(path,"screenshots.png");
BufferedImage image = ImageIO.read(new File("/home/hduser/Desktop/screenshots.png"));
if (!fs.exists(path))
throw new IOException("Output not found!");
ImageIO.write(image, "png", fs.open(path));
}
As asked i have edited here code that i am using to upload image file to hdfs. here ImageIO.write
is not accepting arguement fs.open(path)
, because is asking for file, but i have to give path here as to read and to write to hdfs we need to give path only. Actually i am in need of a method to upload and download file from hdfs using code for all type of data, so i should not write code and use plugins for all type of file.