In this below code I am trying to read the file and then use the pattern to but when using the matcher the output is not coming according to pattern used instead output is coming as the text in the text file
Text File i am using with file name is Names.txt
First off, if you want people to spend the effort to answer your question, put some effort into cleaning up your code (i.e. indent). You may also find your problem that way (hint, line 17). I think you need to start over, there are a number of errors in the code, such as reading in the text but doing nothing more that printing it out.
upanshu vaid wrote:This is the thing I am asking...
Please read the posts of others before you reply. You were asked politely to clean up your indenting, but your next post is even worse than your first.
1. Do NOT use TABs to indent.
2. As Carey already said, you will get more responses if you take the time to clean up your code before you post (you can use the 'Edit' button to do this now that you have).
3. DontWriteLongLines. It makes your posts very hard to read. Yours are OK so far, but the excessive indenting doesn't help.
I'll be happy to help out when I've seen some evidence that you've read our requests.
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
upanshu vaid wrote:Apology Winston , kindly tell the solution to the problem i have mentioned.
OK, well first up: we don't "tell solutions"; we help you to find your own.
So here's a few suggestions:
1. Your indentation is still out of whack (but admittedly, a lot better).
2. What does FileReader.read(char)do?
There's no point in simply using a method in the hope that it'll work. Since the docs, admittedly, aren't great, I'll tell you: In your case, it will read in exactly 90 characters every time it's called, except (probably) the last, since you've supplied it with an array of capacity 90.
3. Line 11 is redundant, since the result of c.length will always be 90.
4. I suspect very strongly that what you're trying to do could be far more easily done with String.split(), so I suggest you look at the docs for that method.
It also sounds like you are trying to code without thinking about what you want to do. I'd advise you to StopCoding (<--click that).
THINK about what you want to do. Only when you know what you want to do should you figure out HOW to do it. Any time someone says "How do I use THIS to do THAT", I am pretty sure they don't know what they want to do, but heard about THIS somewhere in a vaguely related way and now want to use it to solve their problem. It's like someone heard you can use a hammer to build a house. They need to weld some copper pipes together in the house they are building, and now want to know how to use the hammer to weld the pipes together.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I personally prefer to use BufferedReader and its readLine() method when reading text files. Then you will be dealing with Strings as opposed to char arrays. Then if you have a comma separated line of text you might want to use the String split() method instead of regular expressions.