2011-06-24 41 views
1

これで、properties-filesをもう一度使用したかっただけですが、現在はロードできません。私はすでにこの仕事を得るために1時間の仕事を無駄にしていましたが、どういうわけか私はcouldntです。私の問題はthis oneに似ていますが、Javaはファイルを取得しません!プロパティ - ファイルが認識されません!

ここに私のコードです:

パッケージfast.ProfileManager;

import java.io.FileInputStream; import java.util.Properties;

import android.app.Activity; import android.content.Context; import android.net.wifi.WifiManager; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; import android.widget.Toast;

public class PMMain extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     String defaultProfileProperties = "defaultProfile.properties"; 
     Properties properties = new Properties(); 
     properties.load(new FileInputStream(defaultProfileProperties)); 

... 

私はすでにファイル名の前に "/"を挿入しようとしましたが、どちらも失敗しました。

ここに私のプロジェクトディレクトリです:

enter image description here

私はIOExceptionがライン上で取得しています "は、Properties.loadを..."

答えて

3

でプロパティファイルにアクセス/使用するthis introductionをチェックアンドロイド。

// Read from the /assets directory 
try { 
    InputStream inputStream = assetManager.open("defaultProfile.properties""); 
    Properties properties = new Properties(); 
    properties.load(inputStream); 
    System.out.println("The properties are now loaded"); 
    System.out.println("properties: " + properties); 
} catch (IOException e) { 
    System.err.println("Failed to open microlog property file"); 
    e.printStackTrace(); 
} 
:そのリンクに基づいて

は、プロパティは/資産フォルダにファイルを、次のコードを使用して置きます
関連する問題