Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
provide one example what you are providing the input, what it gives the output and what you want to desire from this code ........
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Nick: Again--PLEASE post compilable code. There are three errors in this source.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic