gpt4 book ai didi

java - 调用 getResources().openRawResource() 时出错

转载 作者:行者123 更新时间:2023-12-01 17:34:46 26 4
gpt4 key购买 nike

我必须在 java/eclipse/android 上使用以下代码读取名为 hello.txt 的文件:

import java.io.InputStream;

public class Tokenirzer {
public String ReadPath () {

InputStream inputStream = getResources().openRawResource(R.raw.hello);
}
}

但是我收到以下错误:

The method getResources() is undefined for the type Tokenirzer

我做错了什么?

最佳答案

getResources()Context 的一部分。您可以像在 Activity 中一样使用它,因为它继承自 Context。您需要传入 Activity 的上下文才能使用 getResources

关于java - 调用 getResources().openRawResource() 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7601129/

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