How can I read only text files in a directory.

I wrote a program to play the files in a directory, but I want to let him read the text files from the directory.

import java. IO;

public class {data}

Public Shared Sub main (String [] args) throws IOException {}

String target_dir = "C:\\files";

File dir = new File (target_dir);

File files [] = dir.listFiles ();

for (file textfiles: files) {}

If (textfiles.isFile ()) {}

InputStream BufferedReader = null;

try {}

inputStream = new BufferedReader (new FileReader (textfiles));

String line;

While ((line = inputStream.readLine ())! = null) {}

System.out.println (Line);

}

} {Finally

If (inputStream! = null) {}

inputStream.close ();

}

}

}

}

}

}

You mentioned you want to only read text files.

If you are referring to a specific set of extensions, you can filter on this basis.

ex: you want to only read .txt files, you can add an if condition as below:

          if(textfiles.getName().endsWith(".txt")) {
              // Add your code here
          }

See you soon

AJ

Tags: Java

Similar Questions

  • Can LabVIEW read a text file on Internet?

    I'm using LabVIEW 8.5 and I would read a text unformatted line stored on a web site file (example: www.text.com/test.txt).

    I found that I can not do so using the standard text file reading Subvi. is there a better way?

    Thank you for your help.

    Don't forget form the full url (for example starting with ftp or http).

    You may also need to add the string [text] at the end of the URL. See help.

    Here is an excerpt:

  • Can not read the text file: 7 error file not found

    Hello

    I read a (header.txt) text file that is placed in the same directory as the vi. I use winXP & Labview 8.6. The VI reported an error:

    Error 7 open/create/replace the file in OpenTextFile.vi.

    However, I copied the path of the file at the end of the error message and pasted into the address bar of IE, and I found that IE can open the file.

    Why does this work?

    Thank you

    Ryan

    Never mind. I solved it. I fed the wrong file name in the diagram.

  • How can I save a text file on the disk in Illustrator?

    Hello

    I was looking through the Javascript reference and couldn't find that everything related to the writing of strings in a text file on the disc.

    Is this possible? If so where should I look?

    If not, can I run a piece of code in the Terminal/CommandPrompt in Illustrator (. e.g. echo 'Hello!' > > file.txt)?

    Here's something I think that Muppet Mark or Carlos Canto posted earlier

    #target illustrator
    
    var textFile = File('~/Desktop/AI.txt');
    
    var doc = app.activeDocument;
    
    var docText = '';
    
    for (var i = 0; i < doc.textFrames.length; i++)
         {
              docText += doc.textFrames[i].contents + '\r';
         }
    
    textFile.open('e');
    
    textFile.write(docText);
    
    textFile.close();
    
  • How can I get all the file in a directory name?

    Purpose:

    Try to get all the file in a directory name.

    My code:

    FileConnection fconn = (fileDirectory) Connector.open (FileConnection);
    Listing files = fconn.list ();
    Listing files = fconn.list ("*", true); Try
    _SCREEN.updateDisplay (files); txt shows unreadable.
    String filename = fconn.getName ();
    _SCREEN.updateDisplay1 (fileName); Show WMMS.

    Try using fileconnection.getName (). -->, But fail.

    Could someone give a tip to solve the problem?

    Thank you for your attention,

    You cannot print just an enumeration.
    It is a collection that contains objects, in this case of strings, as you can see on http://www.blackberry.com/developers/docs/7.1.0api/javax/microedition/io/file/FileConnection.html#li...

    You can use a while construct to browse the enum, as:
    While (files.hasMoreElements ()) {}
    System.out.println (files. NextElement());
    }
    (do not know if you do not cast explicitly to a string for sysout, iirc)

  • How can I read my backup files from iPhone 4?

    How to open my saved files to the iPhone 4 that I recorded via iTunes without recover all the data on my device? I need to read the notes and I need a way to read without getting the backup all on my device, is it possible to open iTunes backup files? Thank you it is very important

    Make a backup of your iPhone a current.

    Restore the backup you are interested in.

    When you are finished, you can restore from the current backup again in the first step

  • How can I insert a text file in the body of the message

    I want to insert text in a .txt file in the body of a message in Outlook Express

    I suggest you look into the use of models.
    _ http://KB.mozillazine.org/Thunderbird: _FAQs_:_Using_Templates

    You can also look at some of the model Add-ons that automate some of the https://addons.mozilla.org/en-US/thunderbird/search/?q=templates actions

  • I leave acrobat from adobe, how can I read my PDF files now?

    I can't even open my PDF files without dialog telling me that I need to subscribe first. I think it's pretty ugly, I can't access any PDF on my computer now because once I got adobe acrobat and don't want more. I need help.

    Hi maryh71916491,

    I would like to know exactly which version of the software installed on your system. If you use Acrobat Reader (for viewing PDF free versoion) & trying to make changes with in the Document, and then you will receive this message because PDF files can be edited in Acrobat Pro. So, make sure that you open the file in the appropriate program.

    If you want to just display the pdf file, you can open it in Adobe Reader, you can use this link to download the latest Adobe Reader DC:- Adobe Acrobat Reader DC install for all versions

    Also, you can share the screenshot of the message you are getting.

    Kind regards

    Christian

  • How can I count only text fields that have been used?

    Hello

    I use Livecycle Designer to a dynamic form.  I have a section of the form that contains the field for the user to enter the goals, and then note the purpose.  I want to count only the text fields with entries and have the total number of rates, divided by the number of entries in text field.

    Line 1, column 1 - goal is to collect 5 apples.   Line 1, column 2 - the given rate is 5

    Row 2, column 1 - goal is to collect 5 pears.  Line 1, column 2 - the given rate is 5

    Two goals for a total power of 10-10 divided by 2 = 5

    Is it possible to count only the fields that are populated?

    Also, is it possible to create an error message if the user scored 5 goals but rated only 4 of them?

    Please send me the form to

    [email protected]. I'll get it repaired for you and send it back and then you'll have the code in the form of sample for later reference.

  • Accessory JSP code for only text files

    Hi all
    I want to use the code in the file text on fire to open a text file and parse each line.

    I have a JSP page which I use to attach files. But the JSP attaches files to binary format and so the text file does not recognize these binaries.

    How can he do join text files or how to convert these binary text files?

    My text file code is: -.

    text file = TextFile();
    textFile.open(name: fileHolder.file_filename);

    logMessage ("- file exist? - >" + textFile.exists);

    {foreach (line textFile.lines)
    logMessage ("-The LINE is->" + line);



    }

    textFile.close ();

    And my JSP code is: -.

    < td > < input id = "attachmentFile" type = "file" < f: fieldName att = "fileHolder.file" / > value = "" class = "input" > < table > "

    There is a drawback to doing it this way (many things in memory), but unless the files are big, I suggest to try this:

    // build the string from the file just opened
    stringReadFromFile = String(binary : fileHolder.file, encoding : "ascii")
    

    Once you get it to a string, you might analyze it looking for '\n' line by line. Let me know if you need this code and I'm going to him as well.

    If the files are large, you can store the file in a temporary directory, and then reopen it using text file you described below.

    Dan

  • How can I create a pdf file that is read-only as a resume so that no one can change it

    How can I create a pdf file that is read-only as a resume so that no one can change it

    Hi carolanns81914351,

    You require the Acrobat application for this, see this KB document for the parameters to restrict modification of a PDF Acrobat help. Securing PDF files with passwords.

    Let me know if you have any additional questions.

    Kind regards

    Nicos

  • USB for my iPhone, so it can read a text file

    Hi, I would like to be able to connect a standard USB to my iPhone, so it can read a text file from USB, any suggestions on cable/apps? Thank you, Tony

    Hello. In fact, you can use any USB adapter to connect your iPhone to the computer and transfer text files. Apple recommends the adapter like this http://www.apple.com/shop/product/MD820AM/A/lightning-to-micro-usb-adapter

  • file transfer: How can I send all my files from my office text to my laptop please

    Hi responds to Microsoft

    How can I send all my files from my office text to my laptop please.

    Thank you
    JO

    Copy a USB, external, drive or drive? Then put them on your laptop?

  • How can I search only for Word 2003 document.doc files

    When you enter type in the search box, it returns all Word documents.  How can I specify only the documents in the old format 2003 * .doc?

    Thanks in advance.

    file name: ~ ".doc".

    The : ~ means "must be exact" (if you used just filename: ".doc" without the ~, he would always find the docx for example).

    The * is just a joker and can be used on any version of Windows or DOS.

  • I need a file to an exact width and height and it must be in png format, because it allows to translucency. My graphics are only the top of the page and when I export only the graph is not exported the entire file. How can I get the entire file to ex

    I need a file to an exact width and height and it must be in png format, because it allows to translucency. My graphics are only the top of the page and when I export only the graph is not exported the entire file. How can I get the entire file of export including blank parts?

    in the export dialog box, you have chcked 'use of work plans? ''

Maybe you are looking for

  • even Apple ID on both devices

    Hi, I have a few ipads with the same apple ID. IPad Air 2 are two iPads. The situation here is when I open Safari in one of the iPad showing a small icon at the bottom of the other ipad. If I touch the little icon and drag I can see the iPad another

  • Need drivers for my Satellite L850-B148 and recovery CD

    Where can I get a recovery cd and drivers for my Toshiba Satellite L850 B148? Recently, I had my motherboard and HARD drive replaced, and the freshly installed win7. But unfortunately, I couldn't find the CD that came with the laptop. Can you help me

  • Unlimited music works does not in WALKMAN App 8.3.A.0.2

    I noticed that you have updated the app of WALKMAN to a very clean appearance and style, but there is a major mistake: whenever I try to connect to Unlimited Music, WALKMAN force closes immediately when the widget is trying to regenerate on the homes

  • HP laptop - 15-r263dx: I need to upgrade Win 10 &gt; win 8

    I am tempted to use Win 10 of Microsoft but it too slowly >< but="" idk="" how="" to="" upgrade="" to="" win8="" officials="" again="" ...="" somebody="" can="" help="" me="">

  • validation failure real error hr = 0 x 80070002.

    Original title: genuine validation fails Lately, my W7 Starter netbook starts with a notice that it needs for validation.  The procedure that leads me to d/l and run legitcheck.hta which opens a window telling me to d/l another file... but the link d