나는 'this'를 정적으로 사용하여 명령문을 선언하는 방법은 무엇입니까?
public String readFile(int file)
{
try{
InputStream is = this.getResources().openRawResource(file);
byte[] buffer = new byte[is.available()];
System.out.print(is.available());
System.out.print(is.available());
while (is.read(buffer) != -1)
;
String text = new String(buffer);
return(text);
} catch (Exception e) {
String Ex=" ";
return(Ex);
}
}
파일 읽기 방법-에서 ReadFile()이 원시 폴더에서 파일을 읽고 문자열에 저장하고 그것을 돌려 뒤를 Gridactivity라는 활동을 보유하고 있습니다. 이제 여기서 readFile을 정적으로 만들어야합니다. 하지만 여기서 '
InputStream is = this.getResources().openRawResource(file);
'문은 비 정적입니다. 다른 클래스와 액티비티에서 액세스 할 수 있도록 정적 함수로 만드는 방법은 무엇입니까?
그렇다면이 정적 readFile() 함수를 어떻게 부르겠습니까? 프로그램의 다른 곳에서'InputStream is this.getResources(). openRawResource (file) '문을 사용해야합니다. 이 함수는 호출자 함수와 readFile() 내부에서 액세스 할 수있는 다른 변수에 저장하거나 readFile을 readFile (InputStream is)으로 쉽게 정의하고 'is'를 전달할 수 있습니다. – aProgrammer