I have created a small application, that should get data from Firebase realtime database. The problem is, I will delete all data after get the information from the Firebase. I have searched for the solution, but all the solutions I found did not work for me. I hope you can help me with my problem.
class Example {
public static Object data1;
public static void main(String[] args) throws IOException, InterruptedException {
FileInputStream serviceAccount = new FileInputStream("./google-services.json");
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://example.firebaseio.com")
.build();
CountDownLatch latch = new CountDownLatch(2);
Query reference1 = FirebaseDatabase.getInstance().getReference("/\"UserName\"/"data1");
ref1.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot datasnapshot) {
data1 = datasnapshot.getValue();
System.out.println(data1);
}
@Override
public void onCancelled(DatabaseError databaseError) {
};
});
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("/\"UserName\"");
databaseReference.child("/\"data1\"");
databaseReference.removeValue();
System.out.println("Successfully deleted user");
}