Creating RDF Models:
import org.apache.jena.rdf.model.Model;import org.apache.jena.rdf.model.ModelFactory;import org.apache.jena.rdf.model.Resource;import org.apache.jena.rdf.model.Property; public class JenaExample { public static void main(String[] args) { Model model = ModelFactory.createDefaultModel(); String ns = "http://example.org/"; Resource alice = model.createResource(ns + "Alice"); Property knows = model.createProperty(ns + "knows"); Resource bob = model.createResource(ns + "Bob"); model.add(alice, knows, bob); // Print the model in RDF/XML format model.write(System.out, "RDF/XML"); }}
Loading RDF Data:
model.read("path/to/file.rdf");