• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading In A Resource Folder  RSS feed

 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys Im New to Java, This is actually the second phase of my first program. I'll explain my issue first. I need to read in the contents of a resource folder into my program. Currently it only reads in one file.

Can anyone help, for example my code below is designed to extract the data between two strings and return that data as another string.

For each occurance of said string it is captured and stored within an array, the array is then sorted and its contents are then printed out in a new document.

So basically I now need to test my program against several files rather than just the one.

Can someone please help. thank you for your time, code will follow.
Regards Nick

 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi akhter, im not sure to implement this in my program sorry.

As i mentioned in my post, this is actually an editation made to my first program a few weeks back, i havn't been learning java for very long at all so this is all new to me.

With your suggested code i removed the buffered reader and filereader references from my code, replacing them with your new directory code and had many stack trace errors.

This may sound cheeky but is there any chance you could copy your code into mine as this will give me the best way to reference folders accuractely if I ever need to again in the future.
I plan on documenting the method for my own references.

Thank you very much for your post
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the way you may use



use appropriate perameters while making the object of the class in MAIN
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for that, thats made things alot clearer.

However why can't I use my previous main method

/** main method to find the resource name calling */
public static void main(String[] args) throws IOException {
Find findResources = new Find();
}

I have tried with this but for some reason it throws an error at the n in new Find();

regards Nick
 
tushar bhasme
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's because now there is no Find() constructor ... the constructor signature has now changed to "public Find(String fileName, String begin, String end,String whereToWrite)" ... so you need to pass in the directory name(eg "C:/myDir"), beginning string (eg "<@dynamichtml" ), end string(eg "@>>), targer file name (eg "C:\\Documents and Settings\\Kieren McDonald\\Desktop\\Nick\\Java\\Test\\filetest.txt")...
The code will read all the files present in the folder myDir...

Another thing i would suggest is keep all this code in a method and call it instead of putting it in the constructor...
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok im with you however when i use the method below



I get two errors relating to the directory of my file write destination parameter, why is this?


One says this is not a statment and references the above. The second expects a semi colon ; in the middle of the write path parameter.

regards Nick
 
tushar bhasme
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post the errors?

you may have to use the full path for source directory too (if its not a part of the working directory)...
 
tushar bhasme
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

public Find(String fileName, String begin, String end,String whereToWrite)throws java.io.IOException {"myDir", "<@dynamichtml", "@>", "C:\\Documents and Settings\\Kieren McDonald\\Desktop\\Nick\\Java\\Test\\filetest.txt"}
}


i am not sure what are you trying to achieve by doing the above...

all you need to do is keep the code as it was earlier..

in the main, do this..
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Find.java 93 :not a statement:
public Find(String fileName, String begin, String end,String whereToWrite) throws java.io.IOException {"myDir", "<@dynamichtml", "@>", "C:\\Documents and Settings\\Kieren McDonald\\Desktop\\Nick\\Java\\Test\\filetest.txt"}

error points to s in Desktop

Find.java 93: ';' expected

same except this time points to N in Nick


 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Hang on, I realise I was being a bit of a gimp just then.
I've corrected myself, so now I have



And am getting one error

Find.java93:
Find<java.lang.string.java.lang.string (repeats)
String is already defined in Find

public Find <String fileName, String being, String end, String whereToWrite> throws java.io.IOexception

error points to io ???

regards Nick
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you have right here:


is not valid.

You need to create main method, then create a new Find object using those values inside the main method.

Ex:


Hunter
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok you fixed the last thing I pointed out before I submitted it

What you are doing now is also wrong though.

Inside your find constructor you should be assigning fileName and all of the other class attributes to the values coming in from the constructor. If you just leave the values hardcoded in the constructor you have you will never have an object with different data unless you manually switch the code.

Ex:


Hope this helps,
Hunter
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Morning Hunter, lol when I mentioned before that I was new to Java I Literally Meant brand new lol. Altho i do grasp the concepts of pseudo code and have done bits of coding using javascript and some perl. Java is new to me.

Normally everything I do revolves around html, css, javascript and content management but this is really new to me and I have no teacher so im having to teach myself at the moment.
Anyway i wanted to say thank you, your examples were very helpful.

Altho this morning I read your post from yesterday evening had myself a can of Red Bull and a little read on arguements from the Oracle site and wrote myself a solution lol. I was soo chuffed lol im sure its no biggy but I was pretty happy. Anyway below is what I've used.

Thanks again


 
tushar bhasme
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick,

If you read close, this is exactly what i told you in my last post... you could save a lot of trouble...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!