내 코드에 문제가 있습니까? 저는 Java에 익숙하지 않고 MongoDB로 파일을 가져 오려고합니다. 그러나 나는 그것이 무엇인지 전혀 모른다는 오류가 있습니다. Eclipse를 사용하고 있습니다. 소스 첨부 파일에 JSON.class 파일의 소스가 없습니다.
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
import com.mongodb.util.JSON;
import com.mongodb.util.JSONParseException;
public class readwrite {
public static void main(String[] args) throws FileNotFoundException,IOException,JSONParseException{
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("actualdata");
DBCollection collection = db.getCollection("metadata");
String line = null;
StringBuilder sb = new StringBuilder();
try {
FileInputStream fstream = null;
try {
fstream = new FileInputStream("/home/Output/json1-100000-all");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("File does not exist, exiting");
return;
}
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(fstream));
while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
DBObject dbObject;
sb.append(dbObject = (DBObject) JSON.parse(bufferedReader.readLine()));
collection.insert(dbObject);
DBCursor cursorDoc = collection.find();
while (cursorDoc.hasNext()) {
System.out.println(cursorDoc.next());
}
}
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println("Unable to open file");
}
catch(IOException ex) {
System.out.println(
"Error reading file");
}
}
}
이
내가 그것을 말한다 com.mongodb.util.JSONParser.read (JSON.java:272)에서 클릭했을 때[
Exception in thread "main" com.mongodb.util.JSONParseException:
{
^
at com.mongodb.util.JSONParser.read(JSON.java:272)
at com.mongodb.util.JSONParser.parseObject(JSON.java:230)
at com.mongodb.util.JSONParser.parse(JSON.java:195)
at com.mongodb.util.JSONParser.parse(JSON.java:145)
at com.mongodb.util.JSON.parse(JSON.java:81)
at com.mongodb.util.JSON.parse(JSON.java:66)
at readwrite.main(readwrite.java:45)
표시되는 오류 그것은 나에게이 오류가 표시입니다 소스가 발견되지 않습니다. 원본 첨부 파일에 JSON.class 파일의 소스가 없습니다. DBObject의 변환을 포함하지 않은 경우 BufferedReader의 출력을 인쇄 할 수 있습니다. 미리 감사드립니다!
(이 밖으로 시스템에 디버거 또는 간단한 인쇄를 사용하여 쉽게해야합니다). –
내가 어떻게 할 것이라고 제안 했습니까? – user3414091
대신 http://codereview.stackexchange.com/에 코드를 게시 할 가치가 있습니까? – Trisha