Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.*; import org.xml.sax.*; public class Main { /** Forms an <code>InputSource</code> for parsing XML documents * from a file. Assumes a default character encoding. Returns * <code>null</code> if any of the exceptions is thrown. * * @param fileName The name of the file. * @return An <code>InputSource</code> representation. */ public static InputSource getInputSource(String fileName) { InputSource retVal = null; try { retVal = new InputSource(new BufferedReader(new FileReader(fileName))); } catch (Exception ex) { ex.printStackTrace(); return null; } return retVal; } /** Forms an <code>InputSource</code> for parsing XML documents * from a file. Assumes a default character encoding. Returns * <code>null</code> if any of the exceptions is thrown. * * @param file The file. * @return An <code>InputSource</code> representation. */ public static InputSource getInputSource(File file) { InputSource retVal = null; try { retVal = new InputSource(new BufferedReader(new FileReader(file))); } catch (Exception ex) { ex.printStackTrace(); return null; } return retVal; } /** Forms an <code>InputSource</code> for parsing XML documents * from a file. Returns * <code>null</code> if any of the exceptions is thrown. * * @param fileName The name of the file. * @param enc Character encoding to use. * @return An <code>InputSource</code> representation. */ public static InputSource getInputSource(String fileName, String enc) { InputSource retVal = null; try { retVal = new InputSource(new BufferedReader(new InputStreamReader(new FileInputStream(fileName), enc))); } catch (Exception ex) { ex.printStackTrace(); return null; } return retVal; } /** Forms an <code>InputSource</code> for parsing XML documents * from a file. Returns * <code>null</code> if any of the exceptions is thrown. * * @param file The file. * @param enc Character encoding to use. * @return An <code>InputSource</code> representation. */ public static InputSource getInputSource(File file, String enc) { InputSource retVal = null; try { retVal = new InputSource(new BufferedReader(new InputStreamReader(new FileInputStream(file), enc))); } catch (Exception ex) { ex.printStackTrace(); return null; } return retVal; } }