Im trying to import a file into java, which works with an example import file I found online, but I dont really know how it works. I tryed to write an import file my self but failed. I marked the lines in the code that I dont understand with numbers, so if u could please tell me what the commands mean and do to help me understand it
Question
eccofresh
Im trying to import a file into java, which works with an example import file I found online, but I dont really know how it works. I tryed to write an import file my self but failed. I marked the lines in the code that I dont understand with numbers, so if u could please tell me what the commands mean and do to help me understand it
import java.io.*; class FileImport2 { ? //--------------------------------------------------< main >--------// ? public static void main (String[] args) { ? ?FileImport2 t = new FileImport2(); ? //1 ? ? ?t.readMyFile(); ? ? ?//2 ? } ? //--------------------------------------------< readMyFile >--------// ? void readMyFile() { ? ? ? ? ? ? ? ? ? //3 ? ? ?String record = null; ? ? ?int recCount = 0; ? ? ?try { ? ?FileReader fr ? ? = new FileReader("data.csv"); ? ? ? ? BufferedReader br = new BufferedReader(fr); ?//4 ? ? ? ? record = new String(); ? ? ? ? while ((record = br.readLine()) != null) { ? ? ? ? ? ? ?recCount++; ? ? ? ? ? ?System.out.println(recCount + ": " + record); ? ? ? ? } ? ? ?} catch (IOException e) { ? ? ? ? System.out.println("Uh oh, got an IOException error!"); ? ? ? ? e.printStackTrace(); ? ?//5 ? ? ?} ? } }also, can I import files without exception handling?
thx!
EDIT: also, how would I rewrite that file so that I get an return value that I can use in another class?
Edited by eccofreshLink to comment
Share on other sites
8 answers to this question
Recommended Posts