I have a little problem. I am using NetBeans, and I want to create a program, which will exchange characters in *.csv file.
I was trying to load file on few ways, but I do not now why, it do not works
Code is correct, it can be compiled:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class FixRaports {
public static void main(String[] args) throws FileNotFoundException {
String filePath = "D:/ala.csv";
File fileName = new File(filePath);
Scanner scanner = new Scanner(fileName);
while (scanner.hasNextLine())
{
line = scanner.nextLine();
System.out.println(line);
}
scanner.close();
}
}
Of course, file "ala.csv" is existing on D:\ .
It contains:
Ja "lubie " - placki
bo placki są fajne i "slitasne"
""" My tez je lubimy """
- odpowie ci 'prawie' każdy
"placki ; placki ; ' to jest; to ! """
The code is correctly compiled, but when i play application, it only returns:
run:
BUILD SUCCESSFUL (total time: 0 seconds)
So I tried :
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class FixRaports {
public static void main(String[] args) throws FileNotFoundException {
String filePath = "D:/ala.txt";
File fileName = new File(filePath);
Scanner scanner = new Scanner(fileName);
String line = scanner.nextLine();
System.out.println(line);
scanner.close();
}
}
And the it returns:
run:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at FixRaports.main(FixRaports.java:14)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
I do not understand, why NetBeans returns "No line found" , when file "ala.csv" contains a few lines?
What I am doing wrong?