How do I save it as .txt?

First thing first here is my code I'm playing with.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Component.*;
import java.awt.datatransfer.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;
import javax.swing.filechooser.FileFilter;
public class ExploitExtreme extends JFrame implements ClipboardOwner,ItemListener,ActionListener,MenuListener
  ExploitExtreme()
       super("Exploit Extreme");
     JPopupMenu popup=new JPopupMenu();
     JMenuItem copied=new JMenuItem("Copy");
     JMenuItem pasted=new JMenuItem("Paste");
     JMenuItem delete=new JMenuItem("Clear");
     JTextArea source=new JTextArea(20,50);
  JScrollPane scroll= new JScrollPane(source,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
     JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
     JLabel statusinfo=new JLabel();
     final JFileChooser fc = new JFileChooser();
     JMenuBar menu=new JMenuBar();
     JMenu file=new JMenu("File");
     JMenu options=new JMenu("Options");
     JMenu help=new JMenu("Help");
     //options submenus
     JMenu suboption=new JMenu("More Options..");
     JMenuItem more=new JMenuItem("So I lied");
     JMenuItem tut=new JMenuItem("Tutorial");
     public void init()
       BorderLayout bl=new BorderLayout();
    Container contentArea=getContentPane();
    contentArea.setLayout(bl);
    setVisible(true);
    contentArea.setBackground(Color.red);
    contentArea.add("North",menu);
          contentArea.add("Center",scroll);
          contentArea.add("South",statusinfo);
          menu.add(file);
          menu.add(options);
          menu.add(help);
          //files submenus
          file.add(new AbstractAction("Open")
      public void actionPerformed(ActionEvent event)
                 doOpenCommand();
          file.addSeparator();
          file.add(new AbstractAction("Save As...")
      public void actionPerformed(ActionEvent event)
                 doSaveCommand();
          file.addSeparator();
       file.add(new AbstractAction("Exit")
      public void actionPerformed(ActionEvent event)
        System.exit(0);
          options.add(suboption);
          suboption.add(more);
          help.add(new AbstractAction("About")
            public void actionPerformed(ActionEvent event)
                 JOptionPane. showMessageDialog(null,"Exploit Extreme by Davearia");
          help.addSeparator();
          help.add(new AbstractAction("Tutorial")
      public void actionPerformed(ActionEvent event)
        JOptionPane.showMessageDialog(null,"Here is where I will put together a Tut for this app!");
          //popup.add(copied);
          popup.add(pasted);
          popup.add(delete);
          MouseListener popuplistener=new PopupListener();
          source.addMouseListener(popuplistener);
          copied.addActionListener(this);
          pasted.addActionListener(this);
          delete.addActionListener(this);
     public void menuSelected(MenuEvent evt)
     public void menuDeselected(MenuEvent evt)
     public void menuCanceled(MenuEvent evt)
     public void doOpenCommand()
       FileDialog fd=new FileDialog(ExploitExtreme.this,"Open File",FileDialog.LOAD);
          //fd.setFile("*.java;*.txt");
          fd.show();
          String curfile;
          if((curfile=fd.getFile())!=null)
            String filename=fd.getDirectory()+curfile;
               char[]d;
               setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
               File f=new File(filename);
               try
                 FileReader fr=new FileReader(f);
                    int filesize=(int)f.length();
                    d=new char[filesize];
                    fr.read(d,0,filesize);
                    source.setText(new String(d));
                    statusinfo.setText("Loaded: "+filename);
               catch(FileNotFoundException exc)
                 statusinfo.setText("File Not Found: "+filename);
               catch(IOException exc)
                 statusinfo.setText("IOException: "+filename);
               setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
     public void doSaveCommand()
       FileDialog f=new FileDialog(ExploitExtreme.this,"Save File",FileDialog.SAVE);
          f.show();
          String curfile;
          if((curfile=f.getFile())!=null)
            String filename=f.getDirectory()+curfile+"1";
               setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
               File fi=new File(filename);
               try
                 FileWriter fw=new FileWriter(fi);
                    String text=source.getText();
                    int textsize=text.length();
                    fw.write(source.getText(),0,textsize);
                    fw.close();
                    statusinfo.setText("Saved: "+filename);
               catch(IOException exc)
                 statusinfo.setText("IOException: "+ filename);
               setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
     public void actionPerformed(ActionEvent e)
       if(e.getSource()==delete)
            source.setText("");
       if(e.getSource()==copied)
            copy();
       if(e.getSource()==pasted)
            paste();
     public void copy()
       String s = source.getText();                 
       StringSelection ss = new StringSelection(s);
       this.getToolkit().getSystemClipboard().setContents(ss, this);
       source.selectAll();
     public void paste()
    Clipboard c = this.getToolkit().getSystemClipboard();
       Transferable t = c.getContents(this);
       try
         if (t.isDataFlavorSupported(DataFlavor.stringFlavor))
              String s = (String) t.getTransferData(DataFlavor.stringFlavor);
              source.setText(s);
         else if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
              java.util.List files = (java.util.List)
              t.getTransferData(DataFlavor.javaFileListFlavor);
              java.io.File file = (java.io.File)files.get(0);
              source.setText(file.getName());
       catch (Exception e)
         this.getToolkit().beep();
  public void itemStateChanged(ItemEvent e)
  public void lostOwnership(Clipboard c, Transferable t)
     class PopupListener extends MouseAdapter
    public void mousePressed(MouseEvent e)
       maybeShowPopup(e);
    public void mouseReleased(MouseEvent e)
      maybeShowPopup(e);
    private void maybeShowPopup(MouseEvent e)
      if (e.isPopupTrigger())
        popup.show(e.getComponent(),
        e.getX(), e.getY());
  public static void main(String args[])
       ExploitExtreme ee=new ExploitExtreme();
       ee.init();
       ee.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    ee.setContentPane( ee.getContentPane() );
    ee.setSize(800,600);
    ee.addWindowListener(new java.awt.event.WindowAdapter()
      public void windowClosing(java.awt.event.WindowEvent evt)
        System.exit(0);
    ee.show();
}Sorry it's long winded,the problem I have is that when I save in this app the file is not a text file, so it's a struggle to open it. I need some way of altering my code so the files are saved as .txt files.I believe that the FileFilter class does something similar to this, what is my best bet?

In doSaveCommand(); you wrote
String filename = f.getDirectory() + curfile + "1";
Why don't you append ".txt" ?
It should work with something like
String filename = f.getDirectory() + curfile + "1.txt";

Similar Messages

  • How can i save and load .txt files

    right now i am writing an encryption prog but can't figure out how to save the encrypted text or load encrypted text for decrypting. can someone help me?

    java.io.FileWriter/FileReader

  • How to download a file from the net and save it into .txt format in a datab

    Can some one show me a tutorial on how to download a file from the net and save it into .txt format in a database?
    Thank you,

    http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html

  • How do I save a file as an unformatted txt file instead of html or rtf?

    How do I save a file as an unformatted txt file instead of html or rtf?

    Use menu Image>Image Size in the image size dialog uncheck Resample and enter 300 in the resolution field and click OK.  Note no Pixels are changed only the resolution setting get changed.  The use Menu Fils>Save As in the save as dialog use the file type pull down and select Tiff then click Save
    In the Tiff Option Dialog in the Image Compression  section set None The click OK.

  • Every time I try to download the new version of Adobe Flash Player it saves as a .txt file and I do not know how to get it to save in the correct format.

    Every time I try to download the new version of Adobe Flash Player it saves as a .txt file and I do not know how to get it to save in the correct format.

    Please post in the Adobe Flash Player forum.

  • How can i save the data in a jpanel form to a .txt document

    how can i save the data in a jpanel form to a text file using parse function,this should happen when i click a save button .
    please help me..

    each time when i fill the form and click save button ,all the data in the form should be written to a text file and each time when i repeat it should append to the old data in the text file.the elements in the form should be seperated by pipe delimeter.
    thanks for your patience..

  • How do I save a Numbers spreadsheet in .txt format?

    In order to import a contact list into an online program, I am supposed to Save As a TXT file (text delimited) - I am not given that option.  I have tried numerous ways to save as Excel and convert and cannot find anything that will work.  Please help.

    From my point of view, the easy clean way is to select the table
    copy
    Paste in Textedit
    set format to text
    Save.
    An alternate scheme is this old script :
    --{code}
    --[SCRIPTclipboard2textFile]
    Enregistrer le script en tant que Scriptl :clipboard2textFile.scpt
    déplacer le fichier créé dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:
    Copiez les données à exporter dans le Presse-papiers.
    menu Scripts > clipboard2textFile
    Le script créera un fichier texte.
    --=====
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    +++++++++
    Save the script as a Script, an Application or an Application Bundle:clipboard2textFile.xxx
    Move the newly created file into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:
    Coopy the datas to export into the clipboard
    menu Scripts > clipboard2textFile
    The script will create a text file.
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    +++++++++
    Yvan KOENIG (Vallauris FRANCE)
    7 juillet 2009
    --=====
    on run
              try
                        set enTexte to the clipboard as text
                        set fName to (do shell script "date " & quote & "+_%Y%m%d-%H%M%S.txt" & quote)
                        set p2d to path to desktop
                        tell application "System Events" to make new file at end of p2d with properties {name:fName}
                        write enTexte to file ((p2d as text) & fName)
              on error
                        if my parleAnglais() then
                                  error "The clipboard doesn’t contain text data. Maybe you selected a Numbers sheet !"
                        else
                                  error "Le presse-papiers ne contient pas de données texte. Vous avez peut-être copié une feuille de Numbers !"
                        end if
              end try
    end run
    --=====
    on parleAnglais()
              local z
              try
                        tell application "Numbers" to set z to localized string "Cancel"
              on error
                        set z to "Cancel"
              end try
              return (z is not "Annuler")
    end parleAnglais
    --=====
    --[/SCRIPT]
    Yvan KOENIG (VALLAURIS, France) vendredi 7 octobre 2011 11:15:58
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • How to download & save an archive of musical theatre performances on video?

    This website has archival clippings I would like to download and save: http://www.bluegobo.com/
    and for a particular example to get specific url(s): http://www.bluegobo.com/video/_production.php?var=10094
    I am on Mac mini (not Intel) with 10.4.9
    I have not been able to find a command to Save or download. TubeSock works for YouTube but not for this website. I have VCL and EasyFind but haven't been able to find a tmp file from Safari cache.
    Help, please, I'm stuck. (and there some great archives at Bluegobo.com)!
    Mac mini   Mac OS X (10.4.9)   Mac mini OSX 10.4.9

    Hi
    sadly the link will give hieroglyphics - though it might behave if you had the vlc plugin, but I haven't tested it.
    Let the page of mumbo-jumbo load, then save it from Safari - it may save with a .txt suffix, which you can remove in finder, so it's an xxx.flv file. VLC will then open & play the saved example. ( This I have tested)
    In the first example you gave, I used the Safari View menu, then View Source - look carefully at the code & you'll see "annie98_rosie.flv" I copied this part, then set safari to go to http://www.bluegobo.com/video/annie98_rosie.flv
    For other flv movies on the same site, you would need to view the source, identify and copy the filename which will be in the format flashvars="file=annie98_rosie.flv ( so you copy the part after the = sign up to the .flv )
    Then... if you're doing a few, make a bookmark of http://www.bluegobo.com/video/ open it in Safari, ( you'll get a page not found error, that's ok) and paste the filename you copied onto the end, which is how I got the link I gave which seems like gobbledegook. For each movie, you'd need to do the same - let it finish loading in Safari, save it, lose the txt extension, and then VLC should play it just fine.
    I hope that's a bit clearer - I don't know of any simpler way to suggest.
    Andy
    *EDIT*
    actually, the http://www.bluegobo.com/video/ page gives a Forbidden error - but that's ok too.
    Message was edited by: andyBall_uk

  • I have a pdf file which contains text if i copy all text and paste them into notpad and save file as .txt Is it change the ascii value of text ?

    I have a pdf file which contains text if i copy all text and paste them into notpad and save file as .txt Is it change the ascii value of text ?

    How to know character's encoding is ASCII?

  • How can i save a AWR/statspack report in xml format ??

    how can i save a AWR/statspack report in xml format ?? or is there a way...coz when creating the report it gives option for html or normal (sql or txt based file)... on 10.2.0.3

    thanks orinet....i used wat you asked me to use...it generated a .dmp file....
    sqlplus "/as sysdba"
    SQL> @$ORACLE_HOME/rdbms/admin/awrextr.sql
    i tired upload that file to orapert.com it gives me below error ...any reason why ??
    Error : File not processed because it was too small to be an Oracle statspack or bstat/estat file.
    do i need to load it up too ?? as i tried doing the below
    sqlplus "/as sysdba"
    SQL>@$ORACLE_HOME/rdbms/admin/awrload.sql
    get error while doing that....
    ERROR at line 1:
    ORA-20105: unable to move AWR data to SYS
    ORA-06512: at "SYS.DBMS_SWRF_INTERNAL", line 1760
    ORA-20107: not allowed to move AWR data for local dbid
    ORA-06512: at line 3
    the file is about 19M in size
    Edited by: user630084 on Mar 19, 2009 11:37 AM

  • How can i save the output array of the invoke node "commands values" into a specific file

    I must save the setup of vi commands'. I use an invoke node called "command value" wich give me an array with the name of the specific command and his value. How can i save this array into a specific file to load it later if o need. Must i change the array format?
    Thank you

    Hi,
    I have attached two VIs.
    The first one "Ecriture fichier tableau" (writer) permits to collect all control's values in an array (dbl) and to save it as .bin file. You had to convert variant type into dbl type. (You can do the same with string type if you wish. You will save datas as .txt file for example)
    The second VI "Lecture tableau fichier" (reader) permits to retrieve all the datas you saved in the file.
    I think this responds to your question.
    Regards,
    Attachments:
    Control values.zip ‏26 KB

  • How to set save path using FileStream?

    Hi everybody, I have a webcam that takes a snapshot in AIR. I understand that the code below is to write/edit a .txt file.
    var file:File = File.desktopDirectory.resolvePath( "Text.txt" );
    so how do I save multiple snapshots .jpg to my local network/C drive?

    Hi guys, I have been doing some trial and error and found the correct code to save the bitmap into my C drive. Thanks for reading this thread.
    var fl:File = File.desktopDirectory.resolvePath("C://grpphoto.jpg");
    -Zainuu

  • I am unable to download, Media Downloader. How can I save my tiff files?

    I am unable to download: Media downloader. How can I save my tiff files?

    Hi Barb,
    To investigate this we would have to look at the error logs -
    Start your download and once it gets completed please send us the Log.txt file from the locations listed.
    WIN : C:\Users\<Username>\AppData\Roaming\com.adobe.px.Downloader.<some-num ber>\Local Store\
    MAC : /users/<username>/Library/Preferences/com.adobe.px.Downloader.<some-n umber>/Local Store/
    You can email me the log.txt file at [email protected]
    Thanks,
    Smriti

  • How do i save random numbers?

    below is the coding for random numbers
    public class Random {
    public static void main(String[] args) {
    java.util.Random rand = new java.util.Random();
    for (int i = 0; i < 20; i++) {
    System.out.println(rand.nextInt(10));
    }how do i save the random numbers?????

    That was a quick sample. I'm guessing you're not too familiar with java. I expect the error was because you havn't imported the java.io library.
    import java.io.*;
    public class tester {
      public static void main(String args[]) {
        try {
          PrintWriter out = new PrintWriter(new FileWriter("tmp.txt"));
          java.util.Random rand = new java.util.Random();
          for (int i = 0; i < 20; i++) {
            out.println(rand.nextInt(10));
          out.close();
        } catch (IOException ioe) {
          ioe.printStackTrace();
    }This will compile and run. Notice how you have declared your Random class using java.util.Random? You could have imported java.util.* or java.util.Random then used the declaration 'Random rand = .....' instead (like how i've declared the PrintWriter).
    Rob.

  • How can I save filled Adobe Form?

    Hallo experts,
    I use Adobe Forms in my Webdypro application.
    In Form setPDFSourse set dynamically (read from SAP as byte[]) , I do not know the Context.
    How can I save filled Adobe Form, because I must show the Form by next Step in anothe window? 
    Thank you very much!

    This sounds to me like a client-side problem whith adobe reader plugin in your browser. What is your reader version?
    You can try the following to check if there is any content in the byte[]:
    String s = wdContext.currentContextElement().getPdfData().length + "";
    byte[] test = s.getBytes();
    final IWDCachedWebResource resource =
                   WDWebResource.getWebResource(
                        test,
                        WDWebResourceType.TXT);
    try {
         final IWDWindow window =
         wdComponentAPI.getWindowManager().createExternalWindow(
              resource.getAbsoluteURL(),
              "Window title",
              false);
         window.open();
    } catch (Exception e) {
         wdComponentAPI.getMessageManager().reportException(
         new WDNonFatalException(e),
         false);

Maybe you are looking for

  • Can't download file

    I can upload files in my custom table, but after delete file from default table (i don't why it's flows_020100.WWV_FLOW_FILES) i have "page not found error". Can you help me, and width downloading too.

  • How do I restore Time Machine of my iMac Apps & Files to my MacBook?

    My situation: I have 2 computers (iMac and MacBook Pro). My MacBook Pro has a suite of software that I cannot transfer to my iMac. Why? Because the liscencing was computer specific (foolish me for thinking I could use one lisnence and have it used on

  • How to calculate length of the string in transformation file

    Hello all I have tried a number of ways and I am not able to calculate the length of the incoming field in transformation file for my data load. Here is the issue. I have an incoming string of length 10 and I need to use it to update multiple dimensi

  • Fund Center

    Hi Sapiens, Where do we assign the Authorisation Group for a Fund Center in Fund center Master Data i.e.,Creation of Authoriasation group for a fund center. There are few WBS elements to be settle which are capitalised. I am unable to settle the same

  • How to make show iChat date as well in the log

    iChat shows in the protocol the time. I want also to see the date, because we use iChat mainly for inter office communication and sometimes I want to know at what date a certain message has been sent. How can I get that option set?