Solution : Use DataSet to get the set of all graphs in n-quads file first and use model to get every set.
1: public static void main(String[] args) {
2: // print every Model(Graph) size in n-quads file
3: Model model = ModelFactory.createDefaultModel();
4: Dataset dataset = RDFDataMgr.loadDataset("sample.nq");
5: Iterator it = dataset.listNames();
6: while(it.hasNext()){
7: String graphName = (String) it.next();
8: model = dataset.getNamedModel(graphName);
9: System.out.println(graphName+":"+model.size());
10: }
11: }