11 Replies Latest reply: Sep 28, 2009 12:35 PM by 807580 RSS

    Help. Need code for string verification

    807580
      I am trying to create a swing program that will verify a string then move a directory from a CD to the users hard drive. I have tried many different combinations of code with no success. I simply need a window with a text pane and a button that when clicked copies the content of the windows clipboard into the text pane, then compares it to a predefined string, then moves a directory from a CD to the harddrive.

      It seems very simple but I am new to java, with alot of c++ experiance, and I cant seem to get it to work. If someone could help me out here it would be much apprecaited. Thank you and sorry if I am not using the correct terminology, I tried to be as clear as possible.
        • 1. Re: Help. Need code for string verification
          807580
          You forgot to post the code which didn't work and to tell the problem in detail, now we can't help you in detail.

          My cents on that you used == instead of Object#equals() to compare String objects. It's a common mistake among starters who didn't start with a decent tutorial/book to learn Java.

          For future "New to Java" questions, please use "New to Java" forum and don't forget to post an SSCCE.
          • 2. Re: Help. Need code for string verification
            807580
            So post what you've got (between code tags) and hopefully someone will spot the problem.

            One thing's for sure, nobody is just going to write it for you.
            • 3. Re: Help. Need code for string verification
              791266
              @Op. What part failed, and how did it fail?
              • 4. Re: Help. Need code for string verification
                807580
                Here is the code: I just decided to make it command line instead of a GUI; I had too many problems.

                The code runs fine but for some reason i get this error when you get to the part about copying the file:

                123456789
                Verification complete copying files.
                Exception in thread "main" java.io.FileNotFoundException: C:\copy (Access is denied)
                at java.io.FileInputStream.open(Native Method)
                at java.io.FileInputStream.<init>(FileInputStream.java:106)
                at java.io.FileReader.<init>(FileReader.java:55)
                at CompString.main(CompString.java:20)
                Java Result: 1
                BUILD SUCCESSFUL (total time: 5 seconds)


                Here is the code:

                import java.io.*;
                import java.io.File;
                import java.io.FileReader;
                import java.io.FileWriter;
                import java.io.IOException;

                public class CompString{
                public static void main(String[] args) throws IOException{
                System.out.println("Please go to http://mytatwear.com/verify.html and follow the instructions");
                BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
                System.out.println("Please enter number provided on the website");
                String str1 = bf.readLine();

                String str2 = "123456789";
                if (str1.equals(str2)){
                System.out.println("Verification complete copying files.");
                File inputFile = new File("C:\\copy");
                File outputFile = new File("C:\\tearwear");

                FileReader in = new FileReader(inputFile);
                FileWriter out = new FileWriter(outputFile);
                int c;

                while ((c = in.read()) != -1)
                out.write(c);

                in.close();
                out.close();
                }
                else{
                System.out.println("The number is not valid");
                }
                }
                }


                I had tried to change the permissions on the folder so it is not "Read only" but whenever my program access's it it is for some reason read only.

                Any help apprecaited
                • 5. Re: Help. Need code for string verification
                  807580
                  As one said before, please use code tags to post code. Press the CODE button in the message editor toolbar to get them. Use Preview tab of message editor to check if anything went right.

                  With regard to your problem: I haven't read the code, but according to the exception message it look like that you're trying to get a stream of a folder instead of a file.
                  • 6. Re: Help. Need code for string verification
                    807580
                    I apologize, I had forgotten about the code tags. How would I go about moving a directory, instead of a file. I need to move an entire directory including images and html pages. Thank you for clarifying that.
                    • 7. Re: Help. Need code for string verification
                      807580
                      File#renameTo() ought to be sufficient.
                      • 8. Re: Help. Need code for string verification
                        807580
                        The renameTo function you supplied, would replace what part of the code? I am unsure where is would use the suggested code.
                        • 9. Re: Help. Need code for string verification
                          807580
                          At the moment that you need to rename (move) one folder/file to another folder/file.
                          • 10. Re: Help. Need code for string verification
                            807580
                            Thank you very much program works perfectly now... much appreciated.
                            • 11. Re: Help. Need code for string verification
                              807580
                              You're welcome.