Update: thanks for the quick answers, that's it. I solved the Charset problem, but now something else is happening that I donโt understand at all. Here is my code:
import java.io.*; import java.nio.file.*; import java.nio.charset.*; public class readConvertSeq{ private static String[] getFile(Path file){ String[] fileArray = (String[])Files.readAllLines(file, StandardCharsets.US_ASCII).toArray(); return fileArray; } public static void main(String[] args){ String[] test = readConvertSeq.getFile(Paths.get(args[0])); int i; for(i = 0; i < test.length; i++){ System.out.println(test[i]); } } }
And here is the error:
readConvertSeq.java:6: error: unreported exception IOException; must be caught or declared to be thrown String[] fileArray = (String[])Files.readAllLines(file, StandardCharsets.US_ASCII).toArray();
I'm just trying to get an array of strings from a file, and I'm really disappointed with Java pedantry. Here is my code:
import java.io.*; import java.nio.file.*; import java.nio.charset.*; public class readConvertSeq{ private static String[] getFile(Path file){ String[] fileArray = Files.readAllLines(file, Charset("US-ASCII")).toArray(); return fileArray; } public static void main(String[] args){ String[] test = readConvertSeq.getFile(Paths.get(args[0])); int i; for(i = 0; i < test.length; i++){ System.out.println(test[i]); } } }
This gives me the following:
readConvertSeq.java:6: error: cannot find symbol String[] fileArray = Files.readAllLines(file, Charset("US-ASCII")).toArray(); ^ symbol: method Charset(String) location: class readConvertSeq
I'm sure I made some other mistakes, so feel free to give me any advice.
source share