have been make this programe
to create new file .. and write to file using gui ..
but its not work well
package mainme; import java.io.*; import java.util.Scanner; import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class WriteToFile extends JFrame{ private JTextField text; private JButton ok; private JFrame frame=new JFrame(); public WriteToFile(){ super("Save "); setLayout(new FlowLayout()); text=new JTextField (10); ok=new JButton("ok"); add (text); add(ok); setSize(300,100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); TextHandler handler=new TextHandler(); text.addActionListener(handler); ButtonHandler handlers=new ButtonHandler(); ok.addActionListener(handlers); } private class TextHandler implements ActionListener{ public void actionPerformed(ActionEvent event ){ ok.getAction(); } } private class ButtonHandler implements ActionListener{ public void actionPerformed(ActionEvent event ){ if(event.getSource()==ok) try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String file_name = in.readLine(); File file = new File(file_name); boolean exist = file.createNewFile(); if (!exist) { System.out.println("or append (enter o or a)"); file_name = in.readLine(); // JOptionPane.showMessageDialog(null, "File already exist"); //System.exit(0); } /* else if (exist) { System.out.println("or append (enter o or a)"); file_name = in.readLine();}*/ else { FileWriter fstream = new FileWriter(file_name); BufferedWriter out = new BufferedWriter(fstream); out.write(in.readLine()); out.close(); //System.out.println("File created successfully."); } InputStreamReader convert = new InputStreamReader(System.in); BufferedReader stdin = new BufferedReader(convert); String instr; File outfile = new File(file_name); // boolean append = true; FileWriter fout = new FileWriter(file_name); PrintWriter fileout = new PrintWriter(fout); System.out.print("Enter a string: "); instr = stdin.readLine(); fileout.println(instr); fileout.flush(); fileout.close(); } catch(IOException d) { System.out.println("Error writing to file " + d); }}} public static void main(String[] args) { new WriteToFile(); }}