Android FileOutputStream Write getXMLAsString(File xmlFile, String fileName)

Here you can find the source of getXMLAsString(File xmlFile, String fileName)

Description

get XML As String

Declaration




public static String getXMLAsString(File xmlFile, String fileName) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.InputStream;

public class Main {

    /*public static boolean writeToXml(Context context,String xmlString){ 
           try { /*w  ww.  j  av a  2s. c om*/
               OutputStream out=context.openFileOutput("finance_payment.xml", 
                     Context.MODE_PRIVATE); 
                      
                       
               OutputStreamWriter outw=new OutputStreamWriter(out); 
               try { 
                   outw.write(xmlString); 
                   outw.close(); 
                   out.close(); 
                   return true; 
               } catch (IOException e) { 
                   // TODO Auto-generated catch block 
                   return false; 
               } 
           } catch (FileNotFoundException e) { 
               // TODO Auto-generated catch block 
               return false; 
           } 
       }*/

    /*
     * 
     */
    public static String getXMLAsString(File xmlFile, String fileName) {
        try {
            File file = new File(xmlFile, fileName);
            InputStream inputStream = new FileInputStream(file.getPath());
            StringBuffer outXml = new StringBuffer();
            byte[] b = new byte[4096];
            try {
                for (int n; (n = inputStream.read(b)) != -1;) {
                    outXml.append(new String(b, 0, n));
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return outXml.toString();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. WriteArrayOfStringPairs(FileOutputStream stream, ArrayList> pairs)
  2. WriteInt(FileOutputStream stream, int value)
  3. WriteString(FileOutputStream stream, String text)
  4. saveFileContent(String file, String content, String encode)
  5. Write(String fileName, String message)