title: Jena Sparql output as .txt or .xls file
body: <p>I'm wondering how to create a .txt or .xls file output from the result of Jena SPARQL query. Can anyone help?</p>
  
  <p>here some part of the code</p>
  
  <pre><code>InputStream in = new FileInputStream(new File("./src/myfile.owl"));
  
                  Model model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, null);
                  model.read(in, null);
                  in.close();
  
                  String queryString = 
                          "prefix : &lt;http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#&gt; "  +    
                          "prefix rdfs: &lt;" + RDFS.getURI() + "&gt; "           +
                          "prefix owl: &lt;" + OWL.getURI() + "&gt; "             +
                          "prefix rdf: &lt;" + RDF.getURI() + "&gt; "             +
                          "select  ?Model  " +
                          "where {" +
                          "{?Model rdf:type :ApplicationModel. "      +
                          "?Model :hasDomain ?domain.    "                  +
                          "?domain :domainCode ?domaincode. "               +
                          "FILTER (?domaincode =" + "'"+ domainElement.getAttribute(attrDomain) + "'"+ ")"               +
                          "?Model :hasPhase ?phase." +
                          "?phase :name ?phasecode. "               +
                          "FILTER (?phasecode = "+ "'"+ phaseElement.getAttribute(attrPhase)+"'"+")"  +
                          "?Model :hasLevelOfDetail ?lod." +
                          "?lod :name ?lodcode."               +
                          "FILTER (?lodcode = "+ lodElement.getAttribute(attrLOD) +")"    +
                          "}"
                          ;
                  Query query = QueryFactory.create(queryString);
                  QueryExecution qe = QueryExecutionFactory.create(query, model);
                  ResultSet results = qe.execSelect();
                  ResultSetFormatter.out(System.out, results, query);
                  qe.close();
  
          }
      }
  </code></pre>