Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws FileNotFoundException {
- File file = new File("ValidInvalid.txt");
- String line;
- String[] Title = new String[100];
- String[] Seller = new String[100];
- String[] Writer = new String[100];
- int[] Price = new int[100];
- int[] BarcodeNum = new int[100];
- int counter = 0;
- if (!file.exists()) {
- System.out.print("File not found.");
- System.exit(0);
- }
- try {
- Scanner read = new Scanner(file);
- while (read.hasNextLine()) {
- line = read.nextLine();
- String[] words = line.split(" - ");
- Title[counter] = words[0];
- Writer[counter] = words[1];
- Price[counter] = Integer.parseInt(words[2]);
- Seller[counter] = words[3];
- BarcodeNum[counter] = Integer.parseInt(words[4]);
- System.out.println(Title[counter] + Writer[counter] + Price[counter] + Seller[counter] + BarcodeNum[counter]);
- counter++;
- }
- read.close();
- } catch (NumberFormatException error) {
- }
- }
- while(read.hasNextLine())
- {
- line = read.nextLine();
- String[] words = line.split("-");
- if(words.length == 5)
- {
- Title[counter] = words[0].matches("\s+") ? "No Title" : words[0];
- Author[counter] = words[1].matches("\s+") ? "No Author" : words[1];
- Price[counter] = !words[2].matches("\d+") ? 0 : Integer.parseInt(words[2]);
- Publisher[counter] = words[3].matches("\s+") ? "No Publisher" : words[3];
- ISBN[counter] = !words[4].matches("\d+") ? 0 : Integer.parseInt(words[4]);
- System.out.println(Title[counter] + Author[counter] + Price[counter] + Publisher[counter] + ISBN[counter]);
- counter++;
- }
- else
- {
- System.out.println("Invalid Data format: " + line);
- }
- }
Add Comment
Please, Sign In to add comment