使用C.NET从Hadoop HDFS读取JSON文件

使用C.NET从Hadoop HDFS读取JSON文件,json,hadoop,Json,Hadoop,我试图将json文件从HDFS读取到文件流,但遇到异常 私有字符串ReadHadoopJasonFiles{//set变量字符串destFolderName=/demo/ufo/in; 字符串destFileName=admingroups\u metadata.json //connect to hadoop cluster Uri myUri = new Uri("http://localhost:50070"); string userNam

我试图将json文件从HDFS读取到文件流,但遇到异常

私有字符串ReadHadoopJasonFiles{//set变量字符串destFolderName=/demo/ufo/in; 字符串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\challengeOpenDump20140701160001\u admingroups.json”的一部分。 Source=mscorlib 堆栈跟踪: 在System.IO.\uuu Error.WinIOErrorInt32 errorCode中,字符串maybeFullPath 位于System.IO.FileStream.InitString path、FileMode模式、FileAccess访问、Int32权限、布尔用户权限、FileShare共享、Int32缓冲大小、FileOptions选项、安全属性SECATTR、字符串msgPath、布尔bFromProxy、布尔useLongPath、布尔checkHost 在System.IO.FileStream..ctorString路径、FileMode模式、FileAccess 位于c:\Users\DXG8488\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Program中的ConsoleApplication1.HadoopJsonToRdbms.ReadHadoopJasonFiles。cs:第111行 在c:\Users\DXG8488\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1\Program中的ConsoleApplication1.HadoopJsonToRdbms.JSONTORDBMS控制器上。cs:第29行 在控制台应用程序1.HadoopJsonToRdbms.MainString[]参数中,c:\Users\DXG8488\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:第24行 在System.AppDomain.\u nexecutateAssemblyRuntimeAssembly程序集中,字符串[]args 在System.AppDomain.ExecuteAssemblyString assemblyFile中,证据assemblySecurity,字符串[]args 位于Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly 在System.Threading.ThreadHelper.ThreadStart_ContextObject状态下 位于System.Threading.ExecutionContext.RunInternalExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔值preserveSyncCtx 位于System.Threading.ExecutionContext.RunExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔值preserveSyncCtx 位于System.Threading.ExecutionContext.RunExecutionContext ExecutionContext,ContextCallback回调,对象状态 位于System.Threading.ThreadHelper.ThreadStart InnerException:

我使用 下面是一个读取Json Hadoop REST API的示例

HttpWebRequest req = WebRequest.Create(url_path) as HttpWebRequest;
req.Method = WebRequestMethods.Http.Get; // Get method            
req.Accept = "application/json"; // accept json
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
StreamReader reader = new StreamReader(resp.GetResponseStream());

string result = reader.ReadToEnd();
return result;

文件未找到异常即将出现。对此有何想法?请编辑您的问题以添加异常、异常来源和问题本身。您的问题是什么。学习如何提问