2017-09-28 4 views
0

実行中にファイルをインポートしようとしています。私は、入力フィールドにユーザーの種類のファイル名にアンドロイドInternal storage\Android\data\com.site.myapp\filesUnity3Dを使用してAndroidでランタイム中にファイルをインポートします

にこの場所にファイルf8.csvを入れて、私は、ファイル名を取得し、 その後、私はこのコードを使用してアクセスしてみてください:

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine.UI; 
using UnityEngine; 
using System; 
using System.IO; 

public class ReadAFile : MonoBehaviour 
{ 
    public InputField fileName; 
    public static volatile string file_name; 
    FileInfo f1; 
    public static volatile string message1, message2, message3, path; 
    public static volatile string file_content; 



    public void MyLoad() 
    { 
     file_name = fileName.text.ToString(); 
     f1 = new FileInfo(Application.persistentDataPath + "\\" + file_name); 
     if (f1.Exists) 
     { 

      StreamReader r = File.OpenText(Application.persistentDataPath + "\\" + file_name); 
      string info = r.ReadToEnd(); 
      r.Close(); 
      message1 = "Content of the file is: " + info; 
     } 
     else 
     { 
      message1 = "File not found!"; 
     } 
} 

私は何が間違っているのかわかりませんが、これはうまくいきません。テキストファイルでは機能しません。変更しても機能しませんpersistentDataPathdataPath

+0

「機能しない」とはどういう意味ですか? – lockstock

+0

バックスラッシュの代わりにパスにスラッシュを使用してみてください – lockstock

+0

@lockstockファイルはすべての場合に見つかりません – 2222

答えて

0

WWWを使って必要なものを達成することができました。テキストファイルの場所も変更しました。

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.UI; 
using System.IO; 


public class ImageRead : MonoBehaviour { 

    string url; 

    public void readmyurl() 
    { 

      url = "file:///sdcard/Android/data/f8.txt"; 


    } 

    private void Start() 
    { 

     StartCoroutine(file_read()); 

    } 

    IEnumerator file_read() 
    { 
     readmyurl(); 
     yield return 0; 
     WWW imgLink = new WWW(url); 
     yield return imgLink; 
     message1 = imgLink.text; //message1 is the content of file f8 

    } 



} 
関連する問題