public static String readTextFile(File file) throws IOException {
  FileInputStream inStream=new FileInputStream(file);
  boolean useFallback=false;
  try {
    DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder();
    Document processXmlDocument=documentBuilder.parse(inStream);
    XPathFactory xPathFactory=XPathFactory.newInstance();
    XPath xPath=xPathFactory.newXPath();
    String versionString=xPath.evaluate("/process/@version",processXmlDocument);
    VersionNumber version=new VersionNumber(versionString);
    if (version.isAtMost(5,2,8)) {
      useFallback=true;
    }
  }
 catch (  XPathExpressionException e) {
    useFallback=true;
  }
catch (  SAXException e) {
    useFallback=true;
  }
catch (  ParserConfigurationException e) {
    useFallback=true;
  }
catch (  IOException e) {
    useFallback=true;
  }
catch (  NumberFormatException e) {
    useFallback=true;
  }
  InputStreamReader reader=null;
  try {
    inStream=new FileInputStream(file);
    if (useFallback) {
      reader=new InputStreamReader(inStream);
    }
 else {
      reader=new InputStreamReader(inStream,XMLImporter.PROCESS_FILE_CHARSET);
    }
    return readTextFile(reader);
  }
  finally {
    try {
      inStream.close();
    }
 catch (    IOException e) {
    }
    if (reader != null) {
      try {
        reader.close();
      }
 catch (      IOException e) {
      }
    }
  }
}

public static String readTextFile ( File file ) throws IOException { FileInputStream inStream = new FileInputStream ( file ) ; boolean useFallback = false ; try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder documentBuilder = documentBuilderFactory . newDocumentBuilder ( ) ; Document processXmlDocument = documentBuilder . parse ( inStream ) ; XPathFactory xPathFactory = XPathFactory . newInstance ( ) ; XPath xPath = xPathFactory . newXPath ( ) ; String versionString = xPath . evaluate ( "/process/@version" , processXmlDocument ) ; VersionNumber version = new VersionNumber ( versionString ) ; if ( version . isAtMost ( 5 , 2 , 8 ) ) { useFallback = true ; } } catch ( XPathExpressionException e ) { useFallback = true ; } catch ( SAXException e ) { useFallback = true ; } catch ( ParserConfigurationException e ) { useFallback = true ; } catch ( IOException e ) { useFallback = true ; } catch ( NumberFormatException e ) { useFallback = true ; } InputStreamReader reader = null ; try { inStream = new FileInputStream ( file ) ; if ( useFallback ) { reader = new InputStreamReader ( inStream ) ; } else { reader = new InputStreamReader ( inStream , XMLImporter . PROCESS_FILE_CHARSET ) ; } return readTextFile ( reader ) ; } finally { try { inStream . close ( ) ; } catch ( IOException e ) { } if ( reader != null ) { try { reader . close ( ) ; } catch ( IOException e ) { } } } }
reads a text file into a single string . process files created with rapidminer 5 . 2 . 008 or earlier will be read with the system encoding ( for compatibility reasons ) ; all other files will be read with utf - 8 encoding .
