Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import javax.swing.*;
- import java.lang.*;
- public class loadCommentFiles {
- private static final String DIRECTORY = "comments";
- private static final String DATA_FILENAME = "comments.txt";
- public static void main(String[] args)
- {
- File commentFile = null;
- FileReader fileReader = null;
- BufferedReader bufferedReader = null;
- commentFile = new File(DIRECTORY + "//" + DATA_FILENAME);
- if (commentFile.exists())
- {
- try{
- fileReader = new FileReader(commentFile);
- bufferedReader = new BufferedReader(fileReader);
- String singleLine;
- boolean EOF = false;
- while(EOF == false)
- {
- singleLine = bufferedReader.readLine();
- System.out.println(singleLine);
- int pipeIndex = singleLine.indexOf("|");
- String refNo = singleLine.substring(0, pipeIndex);
- System.out.println(refNo);
- if (singleLine != null){
- }else{
- EOF = true;
- }
- }
- }
- catch(FileNotFoundException ex){
- JOptionPane.showMessageDialog(null, "comments.txt not found " + ex.getMessage(), "Genealogist Helper - File Reader", JOptionPane.ERROR_MESSAGE);
- }catch(IOException ex){
- JOptionPane.showMessageDialog(null, "Error reading file.." + ex.getMessage(), "Genealogist Helper - File Reader", JOptionPane.ERROR_MESSAGE);
- }finally{
- try{
- if (fileReader != null)
- {
- fileReader.close();
- }if(bufferedReader != null)
- {
- bufferedReader.close();
- }
- }catch(IOException ex)
- {
- JOptionPane.showMessageDialog(null, ex.getMessage());
- }
- }
- }else{
- JOptionPane.showMessageDialog(null, "File does no exist!", "Genealogist Helper - File Reader", JOptionPane.ERROR_MESSAGE);
- }
- }
- }
Add Comment
Please, Sign In to add comment