aspose file tools*
The moose likes Beginning Java and the fly likes Why is my string still writing data to my file that i've asked it not to? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why is my string still writing data to my file that i Watch "Why is my string still writing data to my file that i New topic
Author

Why is my string still writing data to my file that i've asked it not to?

Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Basically i have a program to read in the contents of a folder and capture instances of a substring stored between two strings. I want the instances of the substring called "resourceline" to be stored within an array and then sorted and printed into a new document.

However i only want the instances to be stored IF they dont already exist and if the string does not contain certain symbols. I am doing this because i get too much irrelevant data come accross.
The problem is the progam is working but still writing data that i dont want.

please help
regards S

my code is below

akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

provide one example what you are providing the input, what it gives the output and what you want to desire from this code ........


Start Earning Online||Start Earning Using Java
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 189



Use && in place of || and check. Hope it works fine now.


SCJP 5, SCWCD 5
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Prabhakar Reddy Bokka wrote:Use && in place of || and check.

No, that would mean the "blank" code would execute only if *all* of the conditions are met; my understanding is that if *any* of the characters are found it's a match.

(I realize it's hard to tell because of the strange nature of the code.)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Nick: Again--PLEASE post compilable code. There are three errors in this source.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

As I see it, this should follow your requirement about duplicates, but ignore your requirement about special characters. There are two completely unconnected conditionals: the first one, "if (checkContains1...", controls access to an empty block, so it does absolutely nothing. Then the next conditional is tested regardless of the outcome of the first. It checks for duplicates, and otherwise then adds the line to the list.

If your "checkContains" check had a "continue" in it, or if it was attached to the later conditional with an "else", then we'd be getting somewhere.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is my string still writing data to my file that i've asked it not to?
 
Similar Threads
If String Contains (symbols) then call main method
Returning A List Of Variables From A Folder Of Documents And Returning Them Into A New Document
Calling the method from another method within the same class
Substring capture To Write A list Of instances in A New Document
Dumping A string value???