이상하게 들리는 건 알지만 설명 하겠습니다
응용 프로그램이 열리면 온라인 텍스트 파일에서 텍스트를 읽는 BufferedReader 를 성공적으로 만들었지 만 문제는 처음으로 앱을 열면 (에뮬레이터에서) 텍스트를 기록한다는 것입니다 Hello Good World
. 앱을 닫은 후 (일시 중지되지 않음) 서버의 텍스트를 변경하여 Hello Good World 2
.I open the app (In Emulator) and it Logs Hello Good World
. 내 앱을 두 번 다시 시작하려고하지만 여전히 동일한 내용을 기록합니다.
온라인 텍스트가 캐시되고 있다는 증거
Google 크롬에서 URL을 열었을 때 Hello Good World
페이지를 새로 고쳤을 Hello Good World 2
때라 는 텍스트를 보았습니다 . 이제 내 앱을 시작했을 때 (에뮬레이터에서) 표시되었습니다 Hello Good World 2
.
내 코드 :
public class checkRemoteFile extends AsyncTask<Void, Integer, String>{
@Override
protected String doInBackground(Void... params) {
Log.i("Async","Started");
String a = "http://www.standarized.com/ads/Test.txt" ;
StringBuffer result = new StringBuffer();
try{
URL url = new URL(a);
InputStreamReader isr = new InputStreamReader(url.openStream());
BufferedReader in = new BufferedReader(isr);
String inputLine;
while ((inputLine = in.readLine()) != null){
result.append(inputLine);
}
txtFile = result.toString();
Log.i("Buffer", txtFile);
in.close();
isr.close();
}catch(Exception ex){
// result = new StringBuffer("TIMEOUT");
Log.i("Buffer", ex.toString());
}
Log.i("GetStringBuffer(result)", result.toString());
return null;
}
}
당신이 사용하는 경우 URLConnection의를 당신은 사용할 수 있습니다 useCaches
.
그 링크를보세요. 견본:
URL url = new URL("http://www.standarized.com/ads/Test.txt");
URLConnection urlConnection = url.openConnection();
urlConnection.setUseCaches(false);
try {
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline
// character(s)
inputLine = inputLine + str;
}
finally {
in.close();
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다