gpt4 book ai didi

java - 使用 ContentResolver 和 openInputStream() (Android)

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:10:46 24 4
gpt4 key购买 nike

Android 中的新功能和开发类似 This 的应用程序最后遇到了问题 java.io.FileNotFoundException:/document/86: open failed: ENOENT (No such file or directory)现在我正在研究解决方案 “如何使用 ContentResolver 和 openInputStream()”请任何人帮助我如何做到这一点

最佳答案

如果您尝试制作一个从手机读取文件的应用尝试 This

试试这个可能会有帮助

 private InputStream getResources(String s) {
return null;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/plain");
startActivityForResult(intent, 7);
Log.v("###", "parent " + getParent());
}

});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri PathHolder = data.getData();
Log.v("###", "yo " + PathHolder);

super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 7:
if (resultCode == RESULT_OK) {
setContentView(R.layout.activity_main);

try {
InputStream inputStream = getContentResolver().openInputStream(PathHolder);
BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));
String mLine;
while ((mLine = r.readLine()) != null) {
text.append(mLine);
text.append('\n');
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

关于java - 使用 ContentResolver 和 openInputStream() (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52743934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com