FileInputStream code help

Discussion in 'Plugin Development' started by retsrif, Feb 11, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    retsrif

    Hi, would this code work to get information from a text file? tempDB is an ArrayList.
    Code:
    try {
                FileInputStream fis = new FileInputStream(MyPlugin.directory + "text.db");
                DataInputStream dis = new DataInputStream(fis);
                BufferedReader br = new BufferedReader(new InputStreamReader(dis));
                String line = "";
    
                while((line = br.readLine()) != null) {
                    tempDB.add(line);
                }
                fis.close();
            }
            catch (IOException e) {
                System.out.println("Error: " + e.getMessage());
            }
            
     
  2. Offline

    Kekec852

    It would but you could reduce usage of all that streams/readers to only two:
    Code:
    try{
         BufferedReader r = new BufferedReader(new FileReader("file.txt"));
         String line = "";
         while((line = r.readLine()) != null) {
                tempDB.add(line);
          }
         r.close();
    }catch(Exception ex){
         System.out.println("ERROR: " + ex.getMessage());
    }
    
     
  3. Offline

    retsrif

    Thanks.
     
Thread Status:
Not open for further replies.

Share This Page