2011-08-02 7 views
0

jbossのconfディレクトリの下にあるxmlファイルに書きたいと思います。jbossディレクトリにファイルを書き込む

私はこのようにそれを開く:

public void initialiserXml() { 
     sxb = new SAXBuilder(); 

     try { 
        String fileXml= System.getProperty("jboss.server.home.dir").concat("/").concat("/conf").concat("/exempleMessage.xml"); 
      System.out.println("Fichier xml " +fileXml); 
      document = sxb.build(fileXml); 
      racine = document.getRootElement(); 
      System.out.println("Fichier Xml trouvé"); 
     } catch (FileNotFoundException e) { 
     System.err.println("Aucun fichier XML trouvé"); 
     } catch (JDOMException e) { 
      System.err.println("Fichier XML mal construit"); 
     } catch (IOException e) { 
      System.err.println("Impossible d ' ouvrir le fichier XML"); 
     } 
    } 

をし、変更後、私はこの

public void enregistreFichier() 
    { 
     XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); 
     try { 
      sortie.output(document, new FileOutputStream(fileXml)); 
     } catch (FileNotFoundException e) { 
      System.err.println("Fichier XML source non trouvé"); 
     } catch (IOException e) { 
      System.err.println("Impossible d ' ecrire dans le fichier XML"); 
     } 
    } 

状の変化を書く(これは私のテスト環境で動作しますが、私は本番環境でこれをテストするときLinuxサーバー)、それはもはや機能しません。 私はsortie.output(document、new FileOutputStream(fileXml))を渡します。 (FileNotFoundExceptionを)

私はsaxbuilderでそれを開いたときに、私のファイルは、発見され、tは理解ドンが、私は中に書くとき、私はFileNotFoundExceptionを

どのように問題を解決するために持っていてください!

は、ファイルに必要なすべての許可のを持っていないときに、非常に多くの

答えて

0

にFileNotFoundExceptionもスローされありがとう。この場合、/conf/exempleMessage.xmlファイルからの書き込み許可がない可能性があります

"ps -ef | grep jboss"コマンドを実行してjbossを実行しているユーザーを確認する必要があります。文字列jbossを含んでいます。その後、あなたは "chown:/conf/exempleMessage.xml"でファイルの所有権を変更します

+0

また、Linuxでは、ファイルを作成する必要があることを覚えておいてください(ファイルを書き込むときは、新しいファイル'conf'ディレクトリへの書き込み権限も必要です。 –

+0

ありがとう!確かに、それは許可の問題でした。 chmodとchownコマンドでファイルとconfディレクトリにアクセスできました。これで完全に動作します!どうもありがとうございました – user799698

関連する問題