Language: Java I am attempting to find a way to delete over 2,400 lines of a cer
ID: 3692079 • Letter: L
Question
Language: Java
I am attempting to find a way to delete over 2,400 lines of a certain code... I am trying to delete every line except for the bolded lines... Remember each time this code occurs the values may be different. I WOULD LIKE THE FULL CLASS FILE READY TO RUN. The file is called "itemdef.txt" it will be located in the same folder.
This is what the code looks like:
{
"id": 9,
"name": "Different Names",
"desc": "Different Descriptions.",
"value": different values,
"dropValue": 0,
"bonus": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"slot": -1,
"fullmask": false,
"stackable": true,
"noteable": true,
"tradable": true,
"wearable": false,
"showBeard": true,
"members": true,
"twoHanded": false,
"requirements": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
]
},
Thank you very much :)
Explanation / Answer
Hi I first read your string then convert into json and perform remove method. Please test it. You need json jar.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.util.Scanner;
import org.json.JSONObject;
public class ReadText {
public static void main(String[] args) throws IOException, ParseException {
Scanner sc = new Scanner(System.in);
//System.out.print("Enter filename: ");
//String fileName = sc.next();
FileReader fr = new FileReader("itemdef.txt");
BufferedReader br = new BufferedReader(fr);
String finalJson = "";
String line = "";
while((line =br.readLine()) != null){
finalJson += line;
}
br.close();
fr.close();
// converting into json
JSONObject obj = new JSONObject(finalJson);
obj.remove("id");
obj.remove("requirements");
System.out.println(obj.toString());
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.