4

hdfsで利用可能な.propertiesファイルを読み取る必要があります。以下のコードを使用していますが、実行時エラーが発生します。

FileSystem fs = FileSystem.get(config);

    Properties conf = wc.createConfiguration();
    Properties prop = new Properties();
    String appPath = "hdfs://clusterdb05.com:8020/user/cmahajan/" + version + "/apps/apps/";
    conf.setProperty(OozieClient.APP_PATH,appPath);
    FileInputStream f = new FileInputStream("hdfs://clusterdb05.com:8020/user/cmahajan/app.properties");
    ObjectInputStream f = new ObjectInputStream(fs.open(new Path("/user/cmahajan/app.properties")));

実行時エラーは次のとおりです。

LaunchJob.java:28: cannot find symbol

symbol  : class ObjectInputStream
location: class LaunchJob
    ObjectInputStream f = new ObjectInputStream(fs.open(new Path("/user/cmahajan/app.properties")));
    ^
LaunchJob.java:28: cannot find symbol
symbol  : class ObjectInputStream
location: class LaunchJob
    ObjectInputStream f = new ObjectInputStream(fs.open(new Path("/user/cmahajan/app.properties")));
4

2 に答える 2

2

プロパティファイルフォームhdfsをロードする場合:

  1. ur core-site.xmlhdfs-sitexmlファイルパスを確認してください
  2. hdfsポート番号(core-site.xmlで利用可能になります)
  3. getPropertyのキーを置き換えます。

           String CURRENCIES_DIM1 = null;
           String DATES_DIM2 = null; 
           Configuration conf = new Configuration();
            conf.addResource(new Path("/usr/local/hadoop/etc/hadoop/core-site.xml"));
            conf.addResource(new Path("/usr/local/hadoop/etc/hadoop/hdfs-site.xml"));
            String filePath = "hdfs://localhost:54310/user/CurrencyCache.properties";
            Path path = new Path(filePath);
            FileSystem fs = path.getFileSystem(conf);
            try (FSDataInputStream currencyInputStream = fs.open(path)) {
                Properties currencyProp = new Properties();
                currencyProp.load(currencyInputStream);
                CURRENCIES_DIM1= currencyProp.getProperty("key");//getting the 'CURRENCIES_DIM' file path from properties file
                DATES_DIM2= currencyProp.getProperty("key");            //getting the 'DATES_DIM' file path from properties file
    
            } catch (IOException e) {
    
                e.printStackTrace();
            }
            fs.close();
    
于 2015-05-27T12:08:47.073 に答える
0

クラスの完全修飾名を使用します。

java.io.ObjectInputStream 

また

次の行を使用してクラスをインポートします。

import java.io.ObjectInputStream;
于 2012-10-17T11:26:34.353 に答える