Android BufferedReader Create XMLFileToString(String xmlname, Context context)

Here you can find the source of XMLFileToString(String xmlname, Context context)

Description

XML File To String

Declaration

public static String XMLFileToString(String xmlname, Context context) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;
import android.widget.Toast;

public class Main {

    public static String XMLFileToString(String xmlname, Context context) {
        InputStream XML_Stream = null;
        try {/* w w w .j a  v  a  2 s. com*/
            XML_Stream = context.getAssets().open(xmlname);
        } catch (IOException e) {
            Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }

        BufferedReader in = new BufferedReader(new InputStreamReader(
                XML_Stream));
        StringBuffer buffer = new StringBuffer();
        String line = "";
        try {
            while ((line = in.readLine()) != null) {
                buffer.append(line);
            }
        } catch (IOException e1) {
            Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG)
                    .show();
            e1.printStackTrace();
        }
        return buffer.toString();
    }
}

Related

  1. readFileReturnBufferedReader( String filePath, String encoding)