package labList;

import java.io.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;



public class FileIO {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String currentdir = System.getProperty("user.dir");
		JFileChooser chooser = new JFileChooser(currentdir);
		int value = chooser.showOpenDialog(null);
		if (value == JFileChooser.APPROVE_OPTION) {
			File myFile = chooser.getSelectedFile();
			BufferedReader reader;
			try {
				reader = new BufferedReader(new FileReader(myFile));
				while (true) {
					String string = reader.readLine();
					if (string==null) break;
					String[] parts = string.split(":");
					StringBuilder sB = new StringBuilder();
					for (int i=0; i<parts.length; i++) {
						sB.append(parts[i]);
						if (i<parts.length-1) {
							sB.append("_________________");
						}
					}
					String uInput = JOptionPane.showInputDialog(
							"The input is " + sB.toString() + ". Type x to quit.");
					if (uInput.equals("x")) break;
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}
}
