CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Java text file

  1. #1
    Join Date
    Jan 2012
    Posts
    39

    Java text file

    Hi all I did a program containing text files and now I want to make it on a cd. When I did so an error occured when I ran the program from my cd telling me that access is denied. My program is on currently on my USB. How can I change the path of the files to run on my cd. Here is my main code. Any help would be greatly appreciated. Thx in advance

    AVLProcess ap = new AVLProcess();
    AVLTree at = ap.ReadInputFile("E:\\Java files txt\\input.txt", "E:\\Java files txt\\output2.txt");
    String input = JOptionPane.showInputDialog(null, "Please select a number to search");
    Search sr = new Search();

    while (input != null) {
    try {
    Node newNode = sr.search(at.getRoot(), Integer.parseInt(input));
    JOptionPane.showMessageDialog(null, "The node you searched for " + input + " is " + newNode.toString());
    System.exit(0);
    } catch (Exception ex) {
    JOptionPane.showMessageDialog(null, "Please enter a valid number to search next time");
    System.exit(0);
    }


    }

  2. #2
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

  3. #3
    Join Date
    Jan 2012
    Posts
    39

    Re: Java text file

    I don't want this type of answer. I want my answer to the question regardless of the tagging. Can you give it?

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java text file

    I don't want this type of answer.
    Well we don't want code posted without code tags.

    I want my answer to the question regardless of the tagging. Can you give it?
    There is a reason we ask for code to be enclosed in code tags and that's because it makes it easier for us to read your code. We give our valuable time and expertise for free and remember you are asking us for help so the least you can do is make it as easy for us as you possibly can.

    However, if you can't be bothered to help us by using code tags then that's you choice but don't be surprised if we can't be bothered to help you solve your problem.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #5
    Join Date
    Jan 2012
    Posts
    39

    Re: Java text file

    Sorry I will not do it again. Cam you pls help me but?

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java text file

    Post the code wrapped in code tags and I will try to help you.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  7. #7
    Join Date
    Jan 2012
    Posts
    39

    Re: Java text file

    How do I post it pls because I don't know. Forgive me for this time only pls

  8. #8
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: Java text file

    It's in the signature of all the replies you got from keang (and there were quite a few of them). Put your formatted code inside code tags: [code] and [/code].

  9. #9
    Join Date
    Jan 2012
    Posts
    39

    Re: Java text file

    [AVLProcess ap = new AVLProcess();
    AVLTree at = ap.ReadInputFile("E:\\Java files txt\\input.txt", "E:\\Java files txt\\output2.txt");
    String input = JOptionPane.showInputDialog(null, "Please select a number to search");
    Search sr = new Search();

    while (input != null) {
    try {
    Node newNode = sr.search(at.getRoot(), Integer.parseInt(input));
    JOptionPane.showMessageDialog(null, "The node you searched for " + input + " is " + newNode.toString());
    System.exit(0);
    } catch (Exception ex) {
    JOptionPane.showMessageDialog(null, "Please enter a valid number to search next time");
    System.exit(0);
    }


    }
    ]

  10. #10
    Join Date
    Jan 2012
    Posts
    39

    Re: Java text file

    I can't do it sry. Pls help me solving the problem because I'm fed up of trying different solutions

  11. #11
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java text file

    You have to put an opening and closing square bracket with the word 'code' in between them, then your code and finally another opening and closing square bracket with the text '/code' in between them. Not just an opening square bracket, your code and then a closing square bracket.

    Look at the line below this one (particularly the bit in blue lettering) .
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  12. #12
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: Java text file

    If you can't put code tags to your code you should probably start considering a career change. It's not rocket science, just type an opening square bracket [, then the word code, then a closing square bracket ], then type/copy+paste your code, then another opening square bracket [, a forward slash /, followed by the word code, and finally a closing square bracket ].

  13. #13
    Join Date
    Jan 2012
    Posts
    39

    Re: Java text file

    Code:
    AVLProcess ap = new AVLProcess();
    AVLTree at = ap.ReadInputFile("E:\\Java files txt\\input.txt", "E:\\Java files txt\\output2.txt");
    String input = JOptionPane.showInputDialog(null, "Please select a number to search");
    Search sr = new Search();
    
    while (input != null) {
    try {
    Node newNode = sr.search(at.getRoot(), Integer.parseInt(input));
    JOptionPane.showMessageDialog(null, "The node you searched for " + input + " is " + newNode.toString());
    System.exit(0);
    } catch (Exception ex) {
    JOptionPane.showMessageDialog(null, "Please enter a valid number to search next time");
    System.exit(0);
    }
    
    
    }

  14. #14
    Join Date
    Jan 2012
    Posts
    39

    Re: Java text file

    I did it now. Can you pls help me in fixing the problem now pls?

  15. #15
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java text file

    You haven't posted the actual error message but I'm guessing it's because you are trying to write the output file to the CD which you can't do. CD are read only devices as far as your application is concerned.

    Rather than hard coding the file paths into your program either pass the path in on the command line or use a JFileChooser so you can select the input file when the program runs. You may even want to consider displaying the JFileChooser twice, the first time to select the input file and the second time to select where to save the output file.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured