I am trying to run a command from java code two merge to files! The command is:
hadoop fs -cat /user/clouder/Index_1/part-r-00000 /user/cloudera/Index_2/part-r-00000 | hadoop fs -put - /user/cloudera/mergedfile
The command runs perfectly on Cloudera terminal, but when I run the same from java code, it shows the merged content on console but does not create the mergedfile in specified path on HDFS. If the mergedfile is already existing then it outputs the earlier data of the file but not the newly merged data and if the file does not exist then it does not create a new file. Where as the above command running on terminal creates new file if not existing else gives error of file exists.
My java code is as follows:
process p;
try{
p =Runtime.getRuntime().exec("hadoop fs -cat /user/cloudera/Index_1/part-r-00000 /user/cloudera/Index_2/part-r-00000 | hadoop fs -put - /user/cloudera/mergedfile");
BufferredReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
while(s=br.readLine())!=null)
{
System.out.println(s);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
My purpose is replace if there is an existing file or create a new file if not existing from java code.