I have a .txt file named "new.txt" and its content is;
nxy15\nxy995\nxy823\nxy721\nxy1\nxy1872\nxy3482\nxy878\nxy123\nxy8753\nxy1284\nxy4495\nxy4323\nxy812\nxy7123\nxy1273
I need to format that .txt file, to be more specific i need to go to the next line when backslash is detected like one number for each line and i need to remove the letters aswell.
Formatted .txt file needs to look like this;
15
995
823
721
1
1872
...
So far, because of my little Java knowledge, i managed to just read the file and output it. Here it is;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ReadingFile{
public static void main(String[] args) {
try {
File file = new File("C:\\new.txt");
Scanner read = new Scanner(file);
while (read.hasNextLine()) {
String obj2 = read.nextLine();
System.out.println(obj2);
}
read.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
I need to solve this so i can move on to the next question but i'm stuck with this question and can't solve it and i'm trying for three hours.
Any help or clues are highly appreciated, thanks.