0

I am currently working on an application and I have now read in the csv file and am able to paste it out to the user.

I am now however attempting to delete a single row of the csv file or a "log" as the file is supposed to be a data log.

I have been looking around and everywhere is saying something different I am new to java and this is confusing. I hope the following code is helpful.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package itsystem;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.FileReader;
/**
 *
 * @author mccoy
 */
public class ITsystem {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException {
//Scanner object created for users input 
Scanner sc = new Scanner(System.in);
int selection;
//Loop menu while true
while(true){
System.out.println("Menu : ");
System.out.println("Type any number between 1 and 7");
System.out.println("1)Display the full maintenance log");
System.out.println("2)Create new log entry");
System.out.println("3)Edit an existing log entry");
System.out.println("4)Delete an existing log entry");
System.out.println("5)Summary Management information");
System.out.println("6)Save all edits to log file");
System.out.println("7)Exit");
selection = sc.nextInt();
switch (selection)
{
    case 1 :
        // Display maintenance log
        Scanner scFile = new Scanner(new File("C:\\Users\\mccoy\\Documents\\NetBeansProjects\\ITsystem\\src\\itsystem\\log.csv"));
        scFile.useDelimiter(""); //sets the delimiter pattern
        while (scFile.hasNext()) //returns a boolean value
        {
        System.out.print(scFile.next()); //find and returns the next complete token from this scanner
        }
        break;
    case 2 :

        break;
    case 3 : 
        break;
    case 4 :      
        break;
    case 5 :
        break;
    case 6 :
        break;
    case 7 :
        System.out.println("Exiting Program...");
        System.exit(0);
        break;
}   
    }
}

}
  • Better paste your code here than displaying it in a screenshot – Themelis Apr 01 '20 at 21:00
  • [Why not upload images of code on SO when asking a question?](https://meta.stackoverflow.com/q/285551/5221149) – Andreas Apr 01 '20 at 21:02
  • Fixed :) @Themelis – Matty McCoy Apr 01 '20 at 21:03
  • *Unrelated:* You're not closing the file after displaying it. Resource leaks are bad, so you should fix that. – Andreas Apr 01 '20 at 21:04
  • *Unrelated:* Using `Scanner` with `useDelimiter("")` to print the content of the file one character at a time is a bad decision, as it has very bad performance. To read one character at a time, use a `FileReader`. To read lines at a time, use the `hasNextLine()` and `nextLine()` methods of `Scanner`, and print using `println()`. Still `Scanner` is slow for that, so it's better to use a `BufferedReader` and the `readLine()` method for line-reading a text file, and that is much faster than reading character by character. – Andreas Apr 01 '20 at 21:07

0 Answers0