How to search for a particular string in a text file using java?

Let’s learn how to search for a particular string in a text file using java. The most accurate or helpful solution is served by Stack Overflow.

There are ten answers to this question.

Best solution

Search for a String in a Text File using Java 8

I have a long text file that I want to read and extract some data out of it. Using JavaFX and FXML, I am using FileChooser to load the file to get the file path. My controller.java has the following: private void handleButtonAction(ActionEvent event) throws IOException { FileChooser fileChooser = new FileChooser(); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("TXT files (*.txt)", "*.txt"); fileChooser.getExtensionFilters().add(extFilter); File file...

Answer:

Of course you can read the input file as the stream of lines using BufferedReader.lines or Files.lines...

Read more

Moe at Stack Overflow Mark as irrelevant Undo

Other solutions

How to use stop words in a text file so that it does not get counted in a word count program using java?

I have a text file from where the count of each words has to be displayed and words like "to,the,and" should not be counted. I have program for counting but i don't know to use stop words. Any help? This is the count program import java.util...

Answer:

Create a TreeSet and fill it with your stop words. Before entering the logic to increment the frequency...

Read more

Raksani at Yahoo! Answers Mark as irrelevant Undo

Edit text file to search/replace using NEDIT

I am using NEDIT. A text editor on a UNIX system. I need to know how to globally change and Replace some text . The following is an example of a few lines in the text file. N55 LIN(370.855,28.920,-200.827,23.337,-0.183,0.000) ; *XYZ8544 N56 LIN(37...

Answer:

Hello Drcwks Ok, I am familiar with SGI systems running Irix. I at the end of the answer, I have attached...

Read more

drcwks-ga at Google Answers Mark as irrelevant Undo

Does anything know how to read a text file in java wihout using Java Class Library?

I have to write a java program where I should have input from file and there is condition for that, that we cant use Java Class Library. That mean I cant use import java.io stuff. Will appreciate early reply.

Answer:

You mean you can only use the classes in java.lang? or do you mean you can use any except those in java...

Read more

Smart_gi... at Yahoo! Answers Mark as irrelevant Undo

Java: Need help storing String values from text file?

so i have these two text files: text file 1: objectA, name1, name2 objectB, name3, name4 text file 2: objectA name1, name2, name3, name4 objectB name5, name6, name7, name8 I am trying to store all the names for objectA from textfile 1 and 2 into an array...

Answer:

Scanner F1=new Scanner(new File("textfile1")); Scanner F2=new Scanner(new File("textfile...

Read more

Cliff at Yahoo! Answers Mark as irrelevant Undo

Using a String Tokenizer in java with File I/O?

I'm trying to use a StringTokenizer to read from a file and get the information from it. There's a set a names and then a set of numbers. Each name has 5 numbers attached to it. Ex: Johnson 50 60 70 80 90 Frank 60 65 70 75 80 I need to have the names...

Answer:

You can't mix StringBuffer with Scanner. Scanner is the more flexible. int i; double d; boolean b; String...

Read more

Rhendar at Yahoo! Answers Mark as irrelevant Undo

How to write form(HTML Form) data into a Text file using Java-Servlet?

I need to code a Java-Servlet that accept data from a HTML form and write them into a CSV (Comma Separated Value) text file for later import into a database. And also I need to import these text file values in to a spreadsheet package and making sure...

Answer:

use html tags

Read more

Gimhani at Yahoo! Answers Mark as irrelevant Undo

How to search a file using Java?

I am in an introduction to Computer Science class and have to write a program that checks the spelling of words in a text file. I understand how to read each line of the file or to read each line of the dictionary (a text file located in my usr directory...

Answer:

Your question is very important for which I think you should go online and check this out: http://hitechbooks...

Read more

Donna S at Yahoo! Answers Mark as irrelevant Undo

In java how can I delete an item in the text?? using file handling techniques?

I have a text file with Songs, followed by Artists, followed by Categories,, all stored as String arrays. How can I delete a particular element in the array. For example this is my text. Back in Black ACDC Rock Boom P.O.D. Metal American Idiot Green...

Answer:

You cannot delete elements from an array in Java. If you need a more flexible container for data, consider...

Read more

Pillar of Autumn at Yahoo! Answers Mark as irrelevant Undo

Java: How to store string values from a text file?

so i have this text file that is formatted like this ObjectA, name1, name2 ObjectB, name3, name4 ObjectC, name5, name6 i am having trouble trying to save the names and the objects. how would i save these string values with commas that separate them??

Answer:

You can use the next() method of the Scanner class. It will get each word delimited by a white-space...

Read more

Cliff at Yahoo! Answers Mark as irrelevant Undo

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.