M.ArslanKhan
M.ArslanKhan

Reputation: 3918

How to read a Text file from the server

I have A Text file of 15 MB that is available on the server. I don't want tor Download that file. My file is arranged with the index . User search any word from the online file. I am confused about that how i can read online text file, Here is the code that i am using, but there is OutOfMemoryError.

        final Handler mHandlr=new Handler();

        new Thread(new Runnable() {

            @Override
            public void run() {
                String d=getStringFromUrl(TafseerEngPath);
                tafseerTxt.setText(getJSONFromUrl(TafseerEngPath));
                mHandlr.post(new Runnable() {

                    @Override
                    public void run() {
                        tafseerTxt.setText(getJSONFromUrl(TafseerEngPath));
                    }
                });
            }
        }).start();

Error 12-31 18:08:01.100: E/AndroidRuntime(11052): java.lang.OutOfMemoryError

Upvotes: 0

Views: 71

Answers (2)

henry4343
henry4343

Reputation: 3921

try {
   URL url = new URL("http://www.example.com/123.txt");
   Scanner s = new Scanner(url.openStream());
   // read from your scanner
}
catch(IOException ex) {
   // there was some connection problem, or the file did not exist on the server,
   // or your URL was not in the right format.
   // think about what to do now, and put it here.
   ex.printStackTrace(); // for now, simply output it.
}

or

URL url = new URL("http://www.example.com/123.txt");
InputStream in = url.openStream();

Upvotes: 1

Vigbyor
Vigbyor

Reputation: 2604

You have stored your data as Text format and you want to retrieve it as some piece of information at a time. This is not possible with TextFormat ( partially it is possible by creating a webservice ). To avoid this I would like suggest you to store your words in mysql and access the data with webservice.

Android and PHP Web Service.

Upvotes: 1

Related Questions