我试图从hdfs读取json文件到文件流,我得到了一个异常。
私有字符串readhadoopjasonfiles(){//set variables string destfoldername=“/demo/ufo/in”;string destfilename=“admingroups\u metadata.json”;
//connect to hadoop cluster
Uri myUri = new Uri("http://localhost:50070");
string userName = "hadoop";
string srcFilename = destFolderName + "/" + destFileName;
//string srcFilename = @"C:\FilesForHadoopJason\admingroups_metadata.xml";
WebHDFSClient myClient = new WebHDFSClient(Convert.ToString(myUri), userName);
FileStream fs = new FileStream(srcFilename, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
string json;
try
{
json = sr.ReadToEnd();
string repalcedjson = json.Replace("\"", "'");
return repalcedjson;
}
catch (Exception)
{
return null;
}
finally
{
sr.Close();
fs.Dispose();
}
}
异常:system.io.directorynotfoundexception未处理hresult=-2147024893 message=找不到路径“c:\user\projects\poc\challengeOpenUMP20140701160001\u admingroups.json”的一部分。source=mscorlib stacktrace:at system.io.\u error.winioerror(int32 errorcode,string maybefullpath)at system.io.filestream.init(string path,filemode mode,fileaccess access,int32 rights,boolean userights,fileshare,int32 buffersize,fileoptions options,secattrs,string msgpath,boolean bfromproxy,boolean uselongpath,boolean checkhost)在system.io.filestream..ctor(字符串路径,文件模式,c:\users\dxg8488\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\program.cs中consoleapplication1.hadoopjsontordbms.readhadoopjasonfiles()的文件访问权限:c:\users\dxg8488\documents\visual studio中consoleapplication1.hadoopjsontordbms.jsontordbmscontroller()的第111行2012\projects\consoleapplication1\consoleapplication1\program.cs:c:\users\dxg8488\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\program.cs中consoleapplication1.hadoopjsontordbms.main的第29行。\u nexecuteassembly(runtimeassembly,位于system.threading.threadhelper.threadstart\ U上下文(对象状态)的system.appdomain.executeassembly(string assemblyfile,evidence assemblysecurity,string[]args)的microsoft.visualstudio.hostingprocess.hostproc.runusersassembly()的string[]args,在system.threading.executioncontext.run(executioncontext executioncontext,contextcallback callback,object state,boolean preservesyncctx)在system.threading.executioncontext.run(executioncontext executioncontext,contextcallback callback,object state,boolean preservesyncctx)处,对象状态),位于system.threading.threadhelper.threadstart()innerexception:
1条答案
按热度按时间jyztefdp1#
我使用sharphadoop这里是一个阅读json hadoop restapi的例子