This is not a complete, minimal example.
http://stackoverflow.com/help/mcve

Complete: someone else can run the code as-is.
  Not have to hack a bunch of fragments into a program.
  Must compile.

Minimal: just what is needed for the point in query

    Andy




On 16/07/16 16:00, kumar rohit wrote:
Here is the full code,

public static void readOntology(String file,OntModel model)

     {


                     InputStream in =FileManager.get().open(file);



if (in==null) {

throw new IllegalArgumentException( "File: " + file + "  not found");

}

model.read(in,"RDF/XML-ABBREV");

//in.close();



                model.write(System.out);



     }

_______________________________

private static void read1(String str,OntModel model)

     {



   String ns="http://www.semanticweb.org/untitled-ontology-0012/";;

      OntClass user = model.createClass(ns + "User");



      OntClass user1 = model.getOntClass(ns + "User");

     Individual janeSmith = user1.createIndividual(ns + str);



     JOptionPane.showMessageDialog(null, janeSmith.toString());



         try {

            String file="F://hello.owl";





         FileWriter out=new FileWriter(file);

     model.write( out, "RDF/XML-ABBREV" );

  } catch (IOException ex) {

             Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE,
null, ex);

         }

}

_____________________________________________


  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {



OntModel model=ModelFactory.createOntologyModel();

         String str=jTextField2.getText();




       read1(str, model);

}

_________________________________


and finally main()


public static void main(String args[]) {







         OntModel model = ModelFactory.createOntologyModel();

                 String file="F://hello.owl";

readOntology(file , model );

On Sat, Jul 16, 2016 at 6:27 AM, Lorenz B. <
buehm...@informatik.uni-leipzig.de> wrote:

That code doesn't write to disk, so it's impossible.

The only part that COULD write to file, but doesn't is

FileWriter out=new FileWriter(file);



I'm sure that it's not the whole code, so it's impossible to help.
Moreover, it's more a Java related question - nothing for the Jena
mailing list.

Hi

I am very surprised that this code, when executed, has vanished my
ontology
and my ontology is now empty. I copied another ontology and after
executing
few times, again the new ontology is empty. I just want to create the
individual of class and save it locally in the file. There is another
method also in my code but thats just read the file so the main trick is
here. It writed the whole ontology first as model.write() but when GUI
loads and I enter text, again it display output as in
JOptionPane.showMessageDialog() but after the whole exection, the Protege
ontology becomes empty.


*Note: It also create the intended individual but except the User1 class
created in Jena code and its individual, nothing remains in ontology.*



  public static void readOntology(String file,OntModel model)

     {


                     InputStream in =FileManager.get().open(file);



if (in==null) {

throw new IllegalArgumentException( "File: " + file + "  not found");

}

model.read(in,"RDF/XML-ABBREV");

//in.close();



                model.write(System.out);



     }





private static void read1(String str,OntModel model)

     {



   String ns="http://www.semanticweb.org/untitled-ontology-0012/";;

      OntClass user = model.createClass(ns + "User");



      OntClass user1 = model.getOntClass(ns + "User");

     Individual janeSmith = user1.createIndividual(ns + str);



     JOptionPane.showMessageDialog(null, janeSmith.toString());



         try {

            String file="F://hello.owl";





         FileWriter out=new FileWriter(file);

--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center




Reply via email to