Setup JFileChooser to accept text files only.

Hello all, I was trying to setup a JFileChooser to accept only text files, so here's the code:
JFileChooser my_filec = new JFileChooser();
        my_filec.addChoosableFileFilter(new FileFilter()
            public boolean accept(File f)
                return (f.getName().endsWith(".txt")|| !f.getName().contains("."));
            public String getDescription()
                return "Text File (*.txt)";
        });and the problem is if I write <return f.getName().endsWith(".txt")> only it can't open foders and when I write <return (f.getName().endsWith(".txt")|| !f.getName().contains("."));>
it can choose files that doesn't have an extension, is there a way to make it choose ONLY folders and text files?
Another question, can I setup JFileChooser to check the file itself if it was a text file written in ANSI for example REGARDLESS of its extension?

return (f.getName().toLowerCase().endsWith(".txt") || f.isDirectory());You can open the file and check whatever you wish.
The question is how are you going to decide if the file is a text file or not?
You should also try to keep accept function as short as possible or your file chooser will work very slowly.

Similar Messages

  • Notes- Text files only half appear on iPod

    I've added text files to the notes section of my ipod and I save them from word as .txt files, but only half the file appears when I go to read it on my ipod after I've transferred the files. All of the files are like this and the words just cut off at random points during the note. They appear fine when I open them on my computer, but not on the ipod. What's wrong and how do I fix this? Thanks in advance for any advice, I'd really appreciate it!

    Hi.
    I having the same problem.
    I tried saving a note from my laptop in .txt format onto my ipod Calssic 80gb.
    I assume only the first 4kb was saved, as the note on my iPod was truncated. Surely with 80gb, there must be a way in which I could increase the note disk space on the iPod?
    It really would be a tiresome process to keep truncating the original note on my laptop to have it all fit on my iPod.
    Please help.

  • Export to text file only one big page

    We currently have an application that was developed in VB6 that calls a number of Crystal Reports RPT files. These Crystal Reports RPT files were developed in Crystal Reports 6. The problem is that when exporting to TXT format only 1 big page is shown with 1 header, but the report contains multiple pages and headers. When exporting to other formats such as PDF and RTF, the pages and headers are shown correctly.
    Any help would be much appreciated.
    Will.

    Hi William,
    What version are you developing in now?
    Does it work the same in the Reprot Designer as in code?
    Thank you
    Don

  • How to display text file text in aTextArea component

    Hello
    ive managed to display the text file text in the console, but i want it to show up in the textArea component i have in a frame,
    it seems to display the last character . in the text area
    wheres the rest of the text...this was a lot easier in VB.NET
    any help would be much appreciated
    heres my code...
    private void openButtonActionPerformed(java.awt.event.ActionEvent evt)  {//GEN-FIRST:event_openButtonActionPerformed
    // TODO add your handling code here:
         FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files Only","txt");
         editorFileChooser.setFileFilter(filter);
         int returnVal = editorFileChooser.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION){
              System.out.println("You chose to open this file: " + editorFileChooser.getSelectedFile().getName());
              openFileName = editorFileChooser.getSelectedFile().getName();
              openFile = new File(openFileName);
              try {
                   this.readFile = new FileReader(openFile);
              } catch (FileNotFoundException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              int inputCharacters;
         try {
         while ((inputCharacters = readFile.read()) != -1){
              System.out.print((char)inputCharacters);
              char[]CHARAARAY = {(char)inputCharacters};
              s3 = new String(CHARAARAY );
              this.editorTextArea.setLineWrap(true);
         this.editorTextArea.setText(s3.toString());
         readFile.close();
         catch(IOException ex){
              System.out.println();
    }//GEN-LAST:event_openButtonActionPerformed

    >
    wheres the rest of the text...this was a lot easier in VB.NET>If you only need to code for Windows, use VB. For code that works on computers, learn the Java idioms, especially with regard to X-plat issues with Files.
    >
    heres my code...>That was a code snippet. You will get better chance of help around these parts, if you can prepare an SSCCE. The code below* is an SSCCE.
    There was a basic problem in the logic of that code, that resulted in the assumption (by the JRE) that every file the user attempted to load, was located in the 'current directory'. It was fixed by abandoning the String based file name of the file, and instead setting openFile to the selected file in the chooser. I also demolished the loading code by replacing the JTextArea with a JEditorPane (much easier).
    * Altered code;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import java.io.*;
    class TestLoadFile extends JPanel {
      JFileChooser editorFileChooser;
      File openFile;
      JEditorPane editorTextArea;
      TestLoadFile() {
        super(new BorderLayout());
        editorTextArea = new JEditorPane();
        add(
          new JScrollPane(editorTextArea),
          BorderLayout.CENTER );
        JButton load = new JButton("Load File");
        load.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              openButtonActionPerformed(ae);
        add( load, BorderLayout.SOUTH );
        editorFileChooser = new JFileChooser();
      public static void main(String[] args) {
        TestLoadFile tlf = new TestLoadFile();
        JOptionPane.showMessageDialog(null, tlf);
      Dimension preferredSize = new Dimension(600,400);
      public Dimension getPreferredSize() {
        return preferredSize;
      private void openButtonActionPerformed(java.awt.event.ActionEvent evt)  {
        //GEN-FIRST:event_openButtonActionPerformed
      // TODO add your handling code here:
        FileNameExtensionFilter filter = new
          FileNameExtensionFilter("Text Files Only","txt");
        editorFileChooser.setFileFilter(filter);
        int returnVal = editorFileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION){
          System.out.println("You chose to open this file: " +
            editorFileChooser.getSelectedFile().getName());
          // wrong!
          //openFileName = editorFileChooser.getSelectedFile().getName();
          //openFile = new File(openFileName);
          // right!
          openFile = editorFileChooser.getSelectedFile();
          try {
            editorTextArea.setPage(openFile.toURI().toURL());
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
      }//GEN-LAST:event_openButtonActionPerfor
    }

  • I am receiving the data through the rs232 in labview and i have to store the data in to the word file only if there is a change in the data and we have to scan the data continuasly how can i do that.

    i am receiving the data through the rs232 in labview and i have to store the data in to the word or text file only if there is a change in the data. I have to scan the data continuasly. how can i do that. I was able to store the data into the text or word file but could not be able to do it.  I am gettting the data from rs232 interms of 0 or 1.  and i have to print it only if thereis a change in data from 0 to 1. if i use if-loop , each as much time there is 0 or 1 is there that much time the data gets printed. i dont know how to do this program please help me if anybody knows the answer

    I have attatched the vi.  Here in this it receives the data from rs232 as string and converted into binery. and indicated in led also normally if the data 1 comes then the led's will be off.  suppose if 0 comes the corresponding data status is wrtten into the text file.  But here the problem is the same data will be printed many number of times.  so i have to make it like if there is a transition from 1 to o then only print it once.  how to do it.  I am doing this from few weeks please reply if you know the answer immediatly
    thanking you 
    Attachments:
    MOTORTESTJIG.vi ‏729 KB

  • How to write list values to a text file?

    Hi. Does anyone know how to write values stored in a List to a text file? I have a program that asks the user to enter a name and stores it in a list. The number of names in the list depends on how many times the user wants to enter a name. The problem is that my writeToFile method, which handles writing values to a text file, only writes one name and overwrites any previous names. How could I fix this so that it goes thru the list and writes every value to the file? Any hints would be appreciated!
    peace
    Chris
    import java.util.*;
    import java.io.*;
    public class StoreNames
    String name;
    char answer;
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    public void anotherName(List a)throws IOException
    System.out.println("Enter another name? (Y or N)");
    answer = (char)System.in.read();
    System.in.skip(2);
    while(answer == 'Y' || answer == 'y')
    inputName(a);
    System.out.println("Enter another name? (Y or N)");
    answer = (char)System.in.read();
    System.in.skip(2);
    if (answer == 'N' || answer == 'n')
    System.out.println("Ok. GoodBye");
    writeToFile(a);
    //prompts user to input names
    public void inputName(List a) throws IOException
    System.out.print("Enter a name: ");
    name = input.readLine();
    a.add(name);
    public void writeToFile(List a)throws IOException
    PrintWriter output = new PrintWriter(new FileWriter("names.txt"));
    output.print(name); //Problem area - handles only one line of input, overwrites previous input
    output.close();

    System.out is an instance of PrintStream (check the API documents for the System class to see this).
    So the easiest way to convert from a "print to screen" class to a "print to file" class is to acquire a PrintStream that prints to a file, and use it exactly the same as you'd have used System.out...
    So start with your console code...
            PrintStream out = System.out;
            for(int i = 0; i <10; i++){
                out.println("Number " +i);
            }Then you adapt to file code:
            FileOutputStream fos = new FileOutputStream("temp.txt");
            PrintStream out = new PrintStream(fos);
            for(int i = 0; i <10; i++){
                out.println("Number " +i);
            out.flush();
            out.close();Note that we flush the stream because for reasons of efficiency files aren't necessarily written to disk until you explicitly ask the system to do so (memory is fast, disks are slow, that's why).
    Closing the stream releases system resources associated with it.
    Actually, that's redundant, because close calls flush automatically, but I left it in for clarity.
    Any use ?

  • Text file over 200 external email addresses to add to outlook client - Can I import these email addresses to a Group Contact in outlook

    Can i import from a text file (text file only has smtp address) over 200 external email addresses to 2010 outlook client - specifically group contact. I did not see an import button on outlook client.  It would be very convenient if users can manipulate
    a text file which has all their external email addresses import these addresses to one group contact (mailing list)

    Hello Christopher,
    Please follow :-
    Step 1
    Open the text file in a text editor, such as Notepad. Each address should reside on a separate line or be separated by a semicolon. You can include multiple fields, such as names and addresses, by separating the fields by a space or tab.
    Step 2
    Press "Ctrl-A" to select all contacts on the list and then "Ctrl-C" to copy them.
    Step 3
    Click "New Items" from the main Outlook window, "More Items" and then "Contact Group."
    Step 4
    Click "Add Members" and then "From Address Book."
    Step 5
    Click the "Members" field, press "Ctrl-V" to paste the list of emails and click "OK."
    Step 6
    Click the "Name" field and type a name for the group.
    Step 7
    Click "Save & Close" to save your changes.
    Step 8
    Click "New Email" and type the name of the group in the "To" field. You can then compose and send email as usual.

  • During Upgrade - Keep Personal Files Only? or Nothing?

    The help file for Windows 8 Setup says the keep personal files only will keep files under
    \\user\ folder what will happen to folders in the root folder of C:\?.
    Personal files.
    Anything saved in the User folder is considered a personal file, like the Documents and Desktop folders.
    What does it do with the other folders? (Leave, Delete or move to windows.old?)
    If nothing is your choose does this move Root drive files to windows.old?
    Nothing.
    Delete everything and replace your current version with a copy of Windows 8. Your personal files will be moved to a windows.old folder.
    What does it do with the other folders? (Leave, Delete or move to windows.old?)
    Vote for Freedom - Vote to Protect our Country

    Hi,
    Please see “How do I upgrade from Windows 8 Consumer Preview (CP) or Windows 8 Release Preview (RP) to the Released-to-Manufacturing (RTM) version of Windows 8?” in the following thread:
    Windows 8 FAQ
    http://social.technet.microsoft.com/Forums/en-US/w8itprogeneral/thread/7d76e468-192e-4672-8f8e-e78d1446dfaa
    Hope this helps.
    Thanks.
    Nicholas Li
    TechNet Community Support

  • Domain Value Mapping with Text file

    Hai,
    I have done the Domain value mapping with the xml file to xml file and it is working fine.
    But in the case of Text file to Text file it is not working i.e. If the citiname is the
    first field it is domain value mapping and working fine.
    INPUT:
    Erode, Mahes, 22
    Coimbatore, Veera, 22
    OUTPUT:
    ED, Mahes, 22
    CBE, Veera, 22
    But if I change the Citiname to the second column it is not working the problem is
    it is not working for subsequent columns.
    INPUT:
    Mahes, Erode, 22
    Veera, Coimbatore, 22
    OUTPUT:
    Mahes,, 22
    Veera,, 22
    The input Text files are delimited by "comma" and optionally enclosed by "space".
    Does anyone have attained the DVM in the Text file successfully.
    Please help me.

    Thank you for the reply Abhi
    Text to Text means instead of giving the input file as XML file i am giving the input as a simple .txt file and I also want the output in the .txt format.
    For the text file only it is not working fine in the xml file to xml file it is working fine.
    For your another query I am not providing the correct parameters for "lookup-dvm"
    I am giving the xsl file
    <?xml version="1.0" encoding="UTF-8" ?>
    <?oracle-xsl-mapper
    <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
    <mapSources>
    <source type="WSDL">
    <schema location="TextInput1.wsdl"/>
    <rootElement name="Root-Element" namespace="http://TargetNamespace.com/TextInput1"/>
    </source>
    </mapSources>
    <mapTargets>
    <target type="WSDL">
    <schema location="TextOutput1.wsdl"/>
    <rootElement name="Root-Element" namespace="http://TargetNamespace.com/TextInput1"/>
    </target>
    </mapTargets>
    <!-- GENERATED BY ORACLE XSL MAPPER 10.1.3.3.0(build 070615.0525) AT [TUE JUL 15 15:31:55 IST 2008]. -->
    ?>
    <xsl:stylesheet version="1.0"
    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
    xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
    xmlns:pc="http://xmlns.oracle.com/pcbpel/"
    xmlns:ehdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.esb.server.headers.ESBHeaderFunctions"
    xmlns:ns0="http://www.w3.org/2001/XMLSchema"
    xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/"
    xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
    xmlns:imp1="http://TargetNamespace.com/TextInput1"
    xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/file/TextInput1/"
    xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
    xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ora="http://schemas.oracle.com/xpath/extension"
    xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
    xmlns:orcl="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
    xmlns:hdr="http://xmlns.oracle.com/pcbpel/adapter/file/"
    xmlns:ns1="http://xmlns.oracle.com/pcbpel/adapter/file/TextOutput1/"
    exclude-result-prefixes="xsl plt pc ns0 jca imp1 tns hdr ns1 bpws ehdr hwf xp20 xref ora ids orcl">
    <xsl:template match="/">
    <imp1:Root-Element>
    <xsl:for-each select="/imp1:Root-Element/imp1:Leaf-Element">
    <imp1:Leaf-Element>
    <imp1:C1>
    <xsl:value-of select="imp1:C1"/>
    </imp1:C1>
    <imp1:C2>
    <xsl:value-of select='orcl:lookup-dvm("Citinames","Long",imp1:C2,"Short","")'/>
    </imp1:C2>
    <imp1:C3>
    <xsl:value-of select="imp1:C3"/>
    </imp1:C3>
    </imp1:Leaf-Element>
    </xsl:for-each>
    </imp1:Root-Element>
    </xsl:template>
    </xsl:stylesheet>
    Here I am checking the DVM function for the Second column and it is not working and I have given their Inputs and Outputs in my first message .
    I have another question as you told both import and export of the DVM is always in the XML format only so I have a doubt whether the lookup-dvm will be working for xml files only and not for text files.
    But in my case in text file it is working for the first column but not in the subsequent columns.
    Thanks.

  • How do I save an iWeb as text files, XML Sitemaps based on the Sitemap Protocol, or RSS or Atom 1.0 feeds.

    How do I save a web site created in iWeb as something other than HTML. I need to do this because Google will not let me optimize my site as HTML. Google accepts text files, XML Sitemaps based on the Sitemap Protocol, or RSS or Atom 1.0 feeds. Your assistance would be greatly appreciated.

    You mean this ?
    https://developers.google.com/speed/pagespeed/
    First glance. Google does not optimize. It provides suggestions how to optimize.
    You do the optimizing.
    Here's the result of an iWeb page :
    https://developers.google.com/speed/pagespeed/insights#url=http_3A_2F_2Fwww.wyod or.net_2Fmfi_2FMaaskant_2FHow__To.html&mobile=false

  • Why can't i send multiple files through airdrop ? , it accepts but shows only one photo

    why can't i send multiple files through airdrop ? , it accepts but shows only one photo

        Hello there Laurengrayce,
    I message all of the time and I want you to do the same, to anyone you would like!  Demmo provided a good suggestion of having this person check their services and ensuring they're setup as a 10-digit number, but I would like to provide some of my own suggestions.
    If they are in fact already setup as a 10-digit number, I would recommend deleting this persons contact from your phone as well as the entire messaging thread (long press and hold on thread to delete).  Readd them to your contact list and try again.
    Please advise if this continues and they've already checked with their provider.
    Thanks,
    MelissaM_VZW
    Follow us on Twitter @vzwsupport

  • Want to scan to text file on hp oj8600, software indicates only pdf or jpg file creation

    want to scan to text file on hp oj8600, software indicates can do. However printer system software only allows pdf or jpg file type creation.

    Hello @Richf95,
    Welcome to the HP forums.
    I understand that you are trying to save scans as a text file.
    I would like to help.
    PDF has become the standard file type used when scanning/saving a document.
    Most printers will not have text as a default option.
    Try the following:
    Open the HP scan utility
    In the lower left hand corner select 'Create New Shortcut...'
    Name your new short cut. I went with Text.
    In the next window select the file tab.
    In the drop down menu, select Text.
    This should create a shortcut that will allow you to save scans as a .txt file.
    Aardvark1
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!

  • How do I stop TB from including a text file inline, instead of making it only an attachment?

    When I send text files, TB inserts them into the body, as well as attaching the files separately. I don't want them in the body, and I can't find a way not to do that. I've looked all through the options, but the only thing that's close refers to forwarding messages, and changing that did no good. Thank you.

    OK, that explains a little. On my Web-based mail system, the files are attached, not embedded. When I sync that account (IMAP) with TB on my desktop, they're both embedded and attached. Time to look at the options on my desktop.
    On the sending PC, TB shows the sent message with the text as both embedded and attached.
    I've used TB for several years on my desktop, and have never noticed this behavior. I just had to replace the other PC, and changed from Eudora to TB. Maybe all of the options aren't set right, so I'll compare them to my desktop's settings.
    I'm open to more suggestions if you have them.

  • What are some of the best iOS apps can remotely played videos, audios, photos and text files from a NAS hdd connected to Airport Extreme USB port? And how to configure this setup?

    I have already set up NAS hdd as connecting it at USB port of Airport Extreme, i also want to remotely access it from iPhone, so what's the next step? What are some of the best iOS apps can remotely played videos, audios, photos and text files from the NAS hdd and how to configure this setup?

    *Edit - I am not able to connect to the NAS when hardwired to the airport extreme.

  • How can I add a header to a text file without mapping? [Using only ID]

    Hi Experts,
    I am doing a scenario in which I want to add a dynamic header to a text file, due to the complications related to the structure, I dont want to create a message type, data type etc so I cant use mapping.
    I want to do all the manipuations in Integration Directory itself.
    Can you all please help me out in this?
    Thanks in advance
    Thomas

    Hi  Experts,
    I am new to XI, so only elaborate answers would help me
    This is the specific requirement i want;
    There is a 'source text file' which is a collection of 1000+ records, I want to make a 'target file' which is a combination of 2 fields, one field will be the dynamically generated name [for the target file] and the other field will be the whole 'source file' content.
    From the last response for my question, I understand the dynamic file generation part can be done using java mapping.
    Is there anyway by which I can get in the whole content of the source file into a field in the target file?
    Thanks in Advance
    Thomas

Maybe you are looking for

  • Anonymous sequence an clientgen

    Hi there! The clientgen ant-task has problems when using anonymous sequences like <element... <complexType> <sequence maxOccurs="unbounded"> <element name="...".. <element name="...".. </sequence> </complexType> </element> It will generate only one s

  • I updated to iOS 5.0. Now each time I sync the "other" category of memory grows. It is now up to 7.5 GB and I don't have room for videos.

    I updated to iOS 5.0. Now each time I sync the "other" category of memory grows. It is now up to 7.5 GB and I don't have room for videos. I deleted a .3 GB video and the tried to put it back on. Now it says the memory is full. It seems to not release

  • Getting internal table definition

    Hi all, Let's say that I've defined internal table based on internal type (not in dictionary). Does anybody know if there is some FM that could return to me definition of that table (how many fields, their types and so on). For dictionary based type

  • Attach 3rd party application into into installer in C#

    Hi, I am creating an installer using InstallShield in microsoft visual studio. I'm trying to attach/patch third party application into my installer. i have no clue how to do it. Any1 can give me some guidance. Thanks so much. I will appreciate it. 

  • HP550 wireless button Stuck on red?

    Hi Hope someone can help Got an old HP550 notebook it's been fine with nothing going wrong till a couple of days ago. Was installing different flavours of Linux on the laptop, worked fine till I installed a more recent version of Linux Mint. Since th