Android 打开文件失败,清单中的权限已完成
为了让我的应用程序运行,它需要打开一个我保存在手机内存中的txt文件,并使用其中的数据 我已经把许可证放在清单上,在申请表的上面,并且已经把我认为是正确的路径放在上面。程序无法运行,且logcat给出 java.io.FileNotFoundException:/storage/TestDaten/input.txt:open failed:enoint(没有这样的文件或目录) 这是一些代码 在舱单中:Android 打开文件失败,清单中的权限已完成,android,file,android-sdcard,sd-card,Android,File,Android Sdcard,Sd Card,为了让我的应用程序运行,它需要打开一个我保存在手机内存中的txt文件,并使用其中的数据 我已经把许可证放在清单上,在申请表的上面,并且已经把我认为是正确的路径放在上面。程序无法运行,且logcat给出 java.io.FileNotFoundException:/storage/TestDaten/input.txt:open failed:enoint(没有这样的文件或目录) 这是一些代码 在舱单中: 在Android中从sd卡打开文件(供参考) 只需打开主XML文件并粘贴以下代码: <
在Android中从sd卡打开文件(供参考)
只需打开主XML文件并粘贴以下代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My BOOK"
android:onClick="book"/>
</LinearLayout>
现在运行代码
另外,该代码说明了Pdf文件。谢谢您的建议。但是我不想查看内容,我只想使用文件内容进行计算。我需要使用保存的值模拟实时值。
package sel.listG; //package name
import java.io.File;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void book(View v)
{
//your pdf file path
File file=new File("/sdcard/xxxx.pdf");
if(file.exists())
{
Intent i= new Intent(Intent.ACTION_VIEW);
//set pdf to doc if you want to open doc
i.setDataAndType(Uri.fromFile(file), "application/pdf");
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(i);
}
catch(ActivityNotFoundException e)
{
//if pdf reader not found than open browser to download pdf reader
Intent i1=new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.adobe.reader&hl=en"));
startActivity(i1);
}
}
else
{
//if pdf not found on given location
Toast.makeText(getApplicationContext(), "xxxx.pdf not found", Toast.LENGTH_LONG).show();
}
}
}