Question on Files and Exceptions

Hi everyone.
I have a program that is supposed to let you use a JFileSearcher to find a text file, enter some search terms into a JTextArea and when you click a button it opens a new frame. The new frame is it's own class and its constructor requires a file object and an array of Strings. The problem I have is that it isn't reading the file right. I put my readFile() method inside a try clause as well as my Scanner object definition. But, for some reason an exception keeps getting thrown when it tries to execute the readFile() method, which obviously makes the rest of my program not work. Here's my code:
FileSearcher.java
* FileSearcher.java
* Darren Gordon
* @version 1.00 2008/10/18
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class FileSearcher extends JPanel implements ActionListener {
     private JButton find, results, clear;
     private JLabel lblTitle, lblFilePath, lblSearchTerms;
     private JTextField filePath;
     private JTextArea searchTerms;
     private JFileChooser finder;
     private File file;
     private boolean pickedFile = false;
     public static void main(String[] args) {
          new FileSearcher();
    public FileSearcher() {
         JFrame f = new JFrame("D-Train's String File-Searcher, preferred Edition");
         f.setSize(350, 300);
         f.setResizable(false);
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         makePanel();     
         f.add(this);
         f.setVisible(true);
    public void makePanel() {
         try {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
         } catch(Exception e) {
         JPanel top = new JPanel();
         lblTitle = new JLabel("String File-Searcher");
         lblFilePath = new JLabel("Chosen File:");
         filePath = new JTextField(30);
         find = new JButton("Find File");
         JPanel center = new JPanel();
         results = new JButton("Get Results");
         clear = new JButton("Clear Fields");
         lblSearchTerms = new JLabel("Search Terms - seperate with a semi-colon(;)");
         searchTerms = new JTextArea(5, 35);
         finder = new JFileChooser();
         find.addActionListener(this);
         results.addActionListener(this);
         clear.addActionListener(this);
         top.add(lblTitle);
         top.add(lblFilePath);
         top.add(filePath);
         top.add(find);
         top.setPreferredSize(new Dimension(300, 50));
         center.add(lblSearchTerms);
         center.add(searchTerms);
         center.add(results);
         center.add(clear);
         setLayout(new BorderLayout(5, 5));
         add(BorderLayout.NORTH, top);
         add(BorderLayout.CENTER, center);
    public String[] getSearchTerms() {
         String[] temp = searchTerms.getText().split(";");
         return temp;
    public void actionPerformed(ActionEvent e) {
         if(e.getSource() == find) {
              int temp = finder.showOpenDialog(this);
              if(temp == finder.APPROVE_OPTION) {
                   file = finder.getSelectedFile();
                   pickedFile = true;
                   filePath.setText(file.getAbsolutePath());     
         } else if(e.getSource() == clear) {
              searchTerms.setText("");
         } else if(e.getSource() == results && pickedFile) {
              new Results(file, getSearchTerms());
}Results.java
* @(#)Results.java
* Darren Gordon
* @version 1.00 2008/10/18
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class Results extends JPanel {
     private Scanner scan;
     private File file;
     private String[] document, searchTerms;
     private int[] wordsCount;
     private int counter = 0;
     private JLabel lblTitle;
     private JTextArea resultsBox;
     private JScrollPane scroll;
    public Results(File a, String[] s) {
         JFrame f = new JFrame("Search Results");
         f.setResizable(false);
         f.setSize(350, 200);
         searchTerms = s;
         wordsCount = new int[searchTerms.length];
         Arrays.fill(wordsCount, 0);
         file = a;
         try {
              readFile();
         } catch(Exception e) {
              System.out.println("File cannot be read.");
         makePanel();
         findResults();
         giveResults();
         f.add(this);
         f.setVisible(true);
    private void readFile() {
         try {
              scan = new Scanner(file);
         } catch(Exception e) {
              System.out.println("Unable to scan file.");
         while(scan.hasNextLine()) {
              document[counter] = scan.nextLine();
              counter++;
    private void findResults() {
         for(int i = 0; i < searchTerms.length; i++) {
              for(int j = 0; j < counter; j++) {
                    wordsCount[i] = countOccurances(document[j], searchTerms);
private int countOccurances(String line, String search) {
     boolean searching = true;
     int count = 0;
     int index = 0;
     while(searching) {
          index = line.indexOf(search);
          if(index == -1) {
               searching = false;
          } else {
               count++;
               line = line.substring(index + search.length());
     return count;
private void giveResults() {
     for(int i = 0; i < searchTerms.length; i++) {
          if(wordsCount[i] > 0) {
               resultsBox.append("Search term " + searchTerms[i] + " appeared " + Integer.toString(wordsCount[i]) + " time(s).\n");
     resultsBox.append("\nThe rest of the search terms turned up no results.");
private void makePanel() {
     try {     
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
     } catch(Exception e) {
     lblTitle = new JLabel("Search Results");
     resultsBox = new JTextArea(5, 30);
     resultsBox.setLineWrap(true);
     scroll = new JScrollPane(resultsBox, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
     add(lblTitle);
     add(scroll);
}Any ideas why it won't run readFile()?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Ok, basic Exception handling:
Never throw away useful information.
You've got some empty catch blocks: Very, very bad!
You've got some catch blocks that only print a generic message: Bad.
Add at least "e.printStackTrace()" to every catch block.
Then you will see exactly which error occurs and where it happend. That information helps a lot (hint: post it!).

Similar Messages

  • Two questions - embedded files and pdf creation

    I'm wondering if some 'experts' can provide some information? We are a small education company that produce a monthly current events resource for Canadian schools. We provide these resources via mail and also as a pdf file from our website.
    We are not 'experts' by any stretch of the imagination but we have been able to make ID suit our needs and we are learning slowly as we go. Over the summer, we hired a graphics company to refresh our products and we are very happy with the work they did.
    What Im wondering about is they are advising that its bad to have pictures, etc. embedded in ID when creating a pdf file. I have never heard of this and Im wondering if someone can explain why?
    Also, we have always created pdfs by printing a postscript file and then using Distiller to create the pdf, but again Im told that this is not a good idea and that creating the pdf directly from ID is best. I have tried this but the file sizes always seems to be larger and keeping it small is important.
    Thanks in advance for your time.
    Eric Wieczorek

    Hi Robert and Jeffrey
    Thanks for the info and advice. The reason that we have always embedded the files is that the file moves around the office while different people work on it on their own computers. And I also have a home office and I work there sometimes.
    The file is about 30 - 40 pages and there are usually about 20 - 25 images so its just so much easier to embed all the links and just move the one file. We have found this to be the easiest way to work and we have never had any issues . . .

  • Saving with filewriter; no data written to file and exceptions

    I have tried dealing with the exceptions for this by myself. I cant get rid of my null pointer exception and i think i got lost. Also, as it stands, a file gets saved but no data gets saved to that file. I know i shouldnt use a try and catch method for a NULL point exception but i dont think i had a choice because i had to handle other exceptions too, and i cant use an array list because i have been stated to use an array. This is the code anyways and hopefully you can help me onto the right tracks. Cheers.
    private void SaveJButtonActionPerformed( ActionEvent event )
              String fileName=new String("");
              fileName=JOptionPane.showInputDialog("SAVE AS?");
              Album[] printList = myList.getList();
              int i=0;
         for (i=0; i<6; i++)
              try
                   if (printList[i] != null) //checks to see if array item isnt empty
                       final FileWriter outputFile = new FileWriter(fileName);
                        final BufferedWriter outputBuffer = new BufferedWriter(outputFile);
                        final PrintWriter printstream = new PrintWriter(outputBuffer);
                        for (i=0; i<6; i++)
                        printstream.println(printList.printData());
                        printstream.close();
                   else
              System.out.println("");
         catch (FileNotFoundException e)
                   System.err.println("FileNotFoundException: " + e.getMessage());
                   throw new RuntimeException(e);
         catch (IOException e)
                   System.err.println("Caught IOException: "+ e.getMessage());

    you should probably be using
    for (i=0; i<printList.length; i++)
    also, do you really want to print the same thing 6 times in each file?
    for (i=0; i<6; i++)
    printstream.println(printList.printData());

  • Quick question about inheritance and exceptions

    If I have two classes like this:
    public class ClassA {
        public void myMethod() throws NumberFormatException {
          throw new NumberFormatException();
    public class ClassB extends ClassA {
        public void myMethod() {
    }Does myMethod() in classA override myMethod in classB?
    And why?
    Thank you,
    V

    I just want to add that since NumberFormatException is
    a descendant of RuntimeException, you are not required
    to declare that the method throws this exception. Some
    people think it is a good idea to declare it anyway
    for clarity. Personally, I don't think so.I agree.
    I think Sun recommends that you don't declare unchecked exceptions in the method declaration, but do document them in the javadoc comments.

  • Query Log and Exception log

    Hi All,
    I have running essbase application in my system. I execute some query now, what i need to do? to see query log file and exception log file.

    An exception log is only produced if the essbase server or application/database shuts down abnormally, more information :- http://download.oracle.com/docs/cd/E17236_01/epm.1112/esb_dbag/dlogs.html#dlogs1038688
    Query log I provided the details to set up in your previous post :- Log Files
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • My complaints and Questions MP4 M4V video files and other complaints

    My complaints and Questions MP4 M4V video files and other complaints
    I have been scratching my head as to how to fix my problem and I found some answers and some questions along the way. First of all, I have a video that should be correctly formatted for my iPod. Its specs are:
    Kind: MPEG-4 video file
    Size: 19.4 MB
    Bit Rate: 125 kbps
    Date Modified: 8/18/2009 2:15 PM
    Play Count: 1
    Last played: 8/21/2009 12:25 PM
    Profile: Low Complexity
    Channels: Stereo
    Total Bit Rate: 360 kbps
    Video Dimensions: 352x264
    Video Codec: H.264
    F:\File\AnotherFile\A3rdFile\TheMovieFileInQuestion.mp4
    Wow that was a chore. Apple! Let us drag copy and paste our info tabs information so we don’t have to type all this stuff when we are having trouble. **another problem and suggestion** right there.
    Ok, back to the problem of the forum.
    From what I can see from http://www.apple.com/ipodclassic/specs.html this file falls in line of everything required in order to be able to play on my iPod. It plays in iTunes fine but will NOT sync with my iPod. I get an annoying message that states, “Some of the Songs and videos in your iTunes library, including “BlaBlaBlaiPondFixYourJunkBlaBlaBla”, were not copied to the iPod “My iPod” because they cannot be played on this iPod.” Why oh why can iTunes play this video file but my iPod cant. Especially when the specs on Apple’s website say it can.
    So that was bugging me for a LONG time until I found my “Create iPod or iPhone version” option in the “Advanced” heading. Thank goodness this made my files playable on my iPod. Extremely LONG wait though. I know that other programs convert it in ½ the time. But times not to important as long as it gets done, (would be very convenient if it was faster though **Problem and suggestion**)
    Ok, now that I have used the “Create iPod or iPhone version” option it has slowly but surly converted my video. Ok, here is my main problem, the new file which is the result of the conversions information is as follows:
    Kind: MPEG-4 video file
    Size: 35.4 MB
    Bit Rate: 125 kbps
    Date Modified: 8/18/2009 2:15 PM
    Play Count: 1
    Last played: 8/21/2009 1:28 PM
    Profile: Low Complexity
    Channels: Stereo
    Total Bit Rate: 658 kbps
    Video Dimensions: 352x264
    Video Codec: H.264
    C:\File\WhyIsThisNewFileInMyMusicFolder\TheMovieFileInQuestion.m4v
    So basically it has made my file bigger *not a bonus in my book* greatly increased my Bit Rate *another interesting feature*, and I think the biggest change it has changed it from an .mp4 to an m4v.
    Why does it need to be an .m4v I could have sworn some of my videos were or are in mp4 which shouldn’t matter anyway because I was under the impression that iPods could play mp4 files. So that’s my biggest complaint and question. Why can my 80GB classic iPod not play my MP4 files and why am I forced to convert them??
    This conversion also creates 2 files in iTunes when I am done which is annoying because I have to go into my files info and look to see what file is the mp3 in order to remove it. Very annoying I can open my iPod options and see the files and some are faded (the ones it can not play) why can’t I remove them from that area.Suggestion Apple please make files that cannot be played on my iPod stand out some how for easier cleaning Suggestion. Thank you.
    Speaking of cleaning iPods, when I moved my entire library to an external drive I was faced with a terrible problem. “This file could not be found, would you like to locate file”, I was faced with this annoying message at least 600 times. Now I am glad that iTunes has a little “!” mark to show dead links so that you do some minor cleaning, Good Job iTunes No compliant there. However iTunes has no way of selecting all the broken files for major cleaning (like in my case). Going through and deleting over 600 files 1 by 1 is extremely time consuming and annoying. **Suggestion Apple please add more cleaning features for organizing iTunes**.
    Ok, speaking of organization now, another problem that appeared when converting my video files was that it put my new videos into the location where I have all my songs (my external hard drive) why can’t it put the new files in the locations of the original file? I have my computer highly organized and my original files were in that drive in that folder for a reason. If I could open my original file and skip the conversion, my iTunes would go to that specific folder to access the file which is fine. But now these new conversion files are elsewhere taking up space and disorganizing my computer. True I can go into the new location and move the files to where I want them (original location) but I don’t think I should have to hunt them down, copy, move, delete ect etc for all these files over and over. Very annoying, time consuming and should be unnecessary. **Suggestion Make file creation and location more customizable, and user friendly, your customers will love you for it**.
    Well since I have gotten into Apples iTunes and iPod problems that I have had to face I might as well bring up one or two more problems and suggestions. About a month after purchasing my iPod a sibling bought one as well. His however is way more convenient then mine. I suppose he has a 5th gen. so here is my question: why does he have a search option and I don’t!!!! Why does he get more features every so often and I don’t?! Why can’t Apple write some software for us classic guys which got the iPods going! It’s very annoying when I have to spend more time looking for the song then I spend actually listening to it, when he can pull his up in like 3-6 seconds? I highly doubt the hardware between our iPods is that dissimilar and even if they are why cant software be written for us. **Suggestion treat all your customers good not just the newer ones, and make some more features for the classics like me and my iPod.” We will be grateful for it I promise.
    Ok, I am almost done. Let me just recap my questions, I know my post is kind of lengthy.
    #1. Why can’t my iPod play MP3 video files? And why do I have to convert to almost all the same settings except changing it from an mp4 to an m4v. according to Apples own site I should be able to play .m4v .mp4 and .mov files!! Note: remember iTunes plays them fine but my iPod will not.
    #2. Would be much more convenient to be able to copy the information from the windows in iTunes so that problems and trouble shooting would be much easier. A little check on off options in iTunes advanced settings would be terrific.
    #3. Why is the conversion so slow? Please speed it, you have the power. Convenience is the thing that sells products.
    #4. Files that cannot be played on the current iPod need to be easier recognized for simpler cleaning.
    #5. Also make an easier way to select all dead link files for faster cleaning, deleting, etc. This one is important.
    #6. Make a user friendly way to change where my files are going to end up once I convert them for iPod more options and better customizable settings are need.
    #7. One of the most important is ADD A SEARCH OPTION. I and we classics will LOVE Apple for it.
    For you readers, I apologize for the long post, and any grammatical errors you might find throughout it. These are problems that I have faced with these programs and hardware and I wanted to make sure they got acknowledged and hopefully addressed. Any information about why I cannot play MP4 Video files on my iPod would be the best. If anything in my post gets answered that’s the one I want most. Will save me a lot of hassle.
    Thank you all and I look forward to your suggestions and comments. All are welcome and appreciated.
    Sincerely,
    Bond, James

    Was playing with iTunes and thought of another suggestion! Let us play files in iTunes from an iPod! A friend or sibling should be able to plug his iPod into my computer open iTunes and play any of the files there. Many times I have wanted to show a movie clip or video to a friend, and I have the dock so I can do it on my T.V. but play it on their computer in their iTunes forget it. That would be a very nice feature as well so we can watch our movies at maximum size or listen to music on a better sound system, just another suggestion that would be nice. Thanks

  • I used "my documents" for the profile folder, I removed the profile and firefox asked if i want to remove its file, and it took ALL my file except a few, all my photographs etc, are these now unrecoverable? as they are not in the recycle bin

    I used "my documents" for the profile folder, I removed the profile and firefox asked if i want to remove its file, and it took ALL my file except a few, all my photographs etc, are these now unrecoverable? as they are not in the recycle bin
    disaster, thanks firefox 1 year of photos lost

    Thanks for the obvious question. I mean it. The very same thought came to me this morning and, sure enough, I had booted into another drive--my old one that, of course, had the old desktop, etc.
    It didn't dawn on me that this was the case since I hadn't set it as a boot drive but I guess in the course of all the restarts I did, it got switched.
    I'm back to normal again.

  • Files and Streams Question

    Hi! Java is my first and only language; and I am very new to Java. This is my first somewhat knowledgeable attempt to get a question answered on a forum of any kind. I put a question in this forum about two weeks ago, but I lost it. So, I am very grateful for any comments that can improve my ability to get my questions answered. Thank you. Mike
    Here is my problem:
    Read File: I want to read pT.txt or plainText.txt file (that is encoded in Unicode) into a String variable (inputLine).
    (I want to do some processing of the inputLine String and assign the processing results into outputLine.)
    Write File: I want to write outputLine into aPT.txt or anotherPlainText.txt file (that is encoded in ASCII).
    Here is my question:
    What is the simplest or easiest code for the Read File and Write File instructions?
    Thanks. Mike

    Why am I not entering the while loop?
    import java.io.*;
    //not yet: import java.util.Scanner;
    public class FnS
         public static void main(String[] args) throws Exception
              File inFile = new File("pT.txt");
              BufferedReader input = new BufferedReader (new FileReader (inFile));          
              //not yet: PrintWriter outFile = new PrintWriter (new BufferedWriter (new FileWriter ("outFile.txt")));
              String peek1, peek2, peek3, peek4, peek5, peek6;
              boolean pk1 = false, pk2 = false, pk3 = false, pk4 = false, pk5 = false;
              int count = 0;
              while(input.ready())     // begin search
                   peek1  = input.readLine();
                   if (peek1.startsWith("One"))
                        pk1 = true;
                        peek2  = input.readLine();
                        if(pk1 && peek2.startsWith("Two"))
                             pk2 =true;
                             while(pk1 && pk2)
                                  peek3  = input.readLine();
                                  if(pk1 && pk2 && peek3.startsWith("Three"))
                                       pk3 = true;
                                       peek4 = input.readLine();
                                       if(pk1 && pk2 && pk3 && peek4.startsWith("Four"))
                                            pk4 = true;
                                            while(pk1 && pk2 && pk3 && pk4)
                                                 peek5 = input.readLine();
                                                 if(pk1 && pk2 && pk3 && pk4 && peek5.startsWith("Five"))
                                                      pk5 = true;
                                                      peek6 = input.readLine();
                                                      if(pk1 && pk2 && pk3 && pk4 && pk5 && peek6.startsWith("Six"))
                                                            *  (I want to do some processing of the inputLine String and assign the processing results into outputLine.)
                                                            *     Write File:  I want to write outputLine into aPT.txt or anotherPlainText.txt file (that is encoded in ASCII).
                                                            *     Here is my question:
                                                            *  What is the simplest or easiest code for the Read File and Write File instructions?
                                                            *     Thanks.  Mike
                                                           System.out.println("\n" + peek6 + "\n" + peek5 + "\n" + peek4 + "\n" + peek3);
                                                           count++;
                                                           pk1 = false;
                                                           pk2 = false;
                                                           pk3 = false;
                                                           pk4 = false;
                                                           pk5 = false;
                                                           break;
                                                      }//if pk1 && pk2 && pk3 && pk4 && pk5 && peek6
                                                      else
                                                           pk1 = false;
                                                           pk2 = false;
                                                           pk3 = false;
                                                           pk4 = false;
                                                           pk5 = false;
                                                           break;
                                                      }//else begin  new search
                                                 }//if pk1 && pk2 && pk3 && pk4 && peek5
                                            }//while pk1 && pk2 && pk3 && pk4
                                       }// if pk1 && pk2 && pk3 && peek4
                                       else
                                            pk1 = false;
                                            pk2 = false;
                                            pk3 = false;
                                            pk4 = false;
                                            pk5 = false;
                                            break;
                                       }//else begin new search
                                  }//if pk1 && pk2 && peek3
                             }//while pk1 && pk2                              
                        }//if pk1 && peek2
                        else
                             pk1 = false;
                             pk2 = false;
                             pk3 = false;
                             pk4 = false;
                             pk5 = false;
                        }//else begin new search
                   }//if peek1
              }//while hasNext
              System.out.println("\nemail count = " + count);
    }

  • I had a repair done at the apple store where the replaced my hard drive and copied my other hard drive over to the new one.  Everything is fine except the time machine wont reconnect to my old file and is trying create a new file but not enough space?

    I had a repair done at the apple store where the replaced my hard drive and copied my other hard drive over to the new one.  Everything is fine except the time machine wont reconnect to my old file and is trying create a new file but not there is not enough space for both files files? Do I need to do something to have it continue to update my old file instead of recreating a new one?

    Depending on what version of OSX you're running, and how the data was transferred, you may be out of luck.
    If you're running Lion, and your backups were made to a directly-connected external HD (ie, not a Time Capsule or other network location), you may be able to get Time Machine to "associate" the new disk with the old backups.  See #B6 in Time Machine - Troubleshooting, especially the pink box there.
    If you're running Snow Leopard, you might be able to do a full system restore of your backups to the new HD.  See Time Machine - Frequently Asked Question #14 for detailed instructions.  That should leave a "trail" that Time Machine can follow to "associate" the new drive with the old backups.  Unfortunately, that doesn't always work, and there's no way to do it manually, as there is with Lion.

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • Questions about Using Vector To File And JTable

    hi all
    I want to write all data from Vector To File and read from file To Vector
    And I want To show all data from vector to JTable
    Note: I'm using the JBuilder Compiler
    This is Class A that my datamember  And Methods in it
    import java.io.*;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2008</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public  class A implements Serializable {
      int no;
      String name;
      int age;
      public void setA (int n,String na,int a)
        no=n;
        name=na;
        age=a;
      public void set_no(int n)
        no = n;
      public void set_age(int a)
        age = a;
        public int getage ()
        return age;
      public void setName(String a)
        name  = a;
      public String getname ()
        return name;
      public int getno ()
        return no;
    This is The Frame That the JTextFeild And JButtons & JTable in it
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import com.borland.jbcl.layout.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2008</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class Frame1 extends JFrame {
    /* Vector v = new Vector ();
      public int i=0;*/
      A a = new A();
      XYLayout xYLayout1 = new XYLayout();
      JTextField txtno = new JTextField();
      JTextField txtname = new JTextField();
      JTextField txtage = new JTextField();
      JButton add = new JButton();
      JButton search = new JButton();
      /*JTable jTable1 = new JTable();
      TableModel tableModel1 = new MyTableModel(*/
                TableModel dataModel = new AbstractTableModel() {
              public int getColumnCount() { return 2; }
              public int getRowCount() { return 2;}
              public Object getValueAt(int row, int col) { return new A(); }
          JTable table = new JTable(dataModel);
          JScrollPane scrollpane = new JScrollPane(table);
      TitledBorder titledBorder1;
      TitledBorder titledBorder2;
      ObjectInputStream in;
      ObjectOutputStream out;
      JButton read = new JButton();
      public Frame1() {
        try {
          jbInit();
        catch(Exception e) {
          e.printStackTrace();
      private void jbInit() throws Exception {
        titledBorder1 = new TitledBorder(BorderFactory.createEmptyBorder(),"");
        titledBorder2 = new TitledBorder("");
        this.getContentPane().setLayout(xYLayout1);
        add.setBorder(BorderFactory.createRaisedBevelBorder());
        add.setNextFocusableComponent(txtno);
        add.setMnemonic('0');
        add.setText("Add");
        add.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            add_actionPerformed(e);
        add.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            add_actionPerformed(e);
        search.setFocusPainted(false);
        search.setText("Search");
        search.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            search_actionPerformed(e);
        xYLayout1.setWidth(411);
        xYLayout1.setHeight(350);
        read.setText("Read");
        read.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            read_actionPerformed(e);
        this.getContentPane().add(txtno, new XYConstraints(43, 35, 115, 23));
        this.getContentPane().add(txtname,  new XYConstraints(44, 67, 114, 22));
        this.getContentPane().add(txtage,      new XYConstraints(44, 97, 115, 23));
        this.getContentPane().add(add,      new XYConstraints(60, 184, 97, 26));
        this.getContentPane().add(search,  new XYConstraints(167, 185, 88, 24));
        this.getContentPane().add(table,   new XYConstraints(187, 24, 205, 119));
        this.getContentPane().add(read,   new XYConstraints(265, 185, 75, 24));
        this.setSize(450,250);
        table.setGridColor(new Color(0,0,255));
      void add_actionPerformed(ActionEvent e)
        a.set_no(Integer.parseInt(txtno.getText()));
        a.setName(txtname.getText());
        a.set_age(Integer.parseInt(txtage.getText()));
        fileOutput();
        txtno.setText(null);
        txtname.setText(null);
        txtage.setText(null);
        try
          out.writeObject(a);
          out.close();
        }catch (Exception excep){};
    /*  try
           add.setDefaultCapable(true);
          v.addElement(new A());
         ((A)v.elementAt(i)).setA(Integer.parseInt(txtno.getText()),txtname.getText(),Integer.parseInt(txtage.getText()));
        JOptionPane.showMessageDialog(null,"The Record is Added");
        txtno.setText(null);
        txtname.setText(null);
        txtage.setText(null);
        i++;
      }catch (Exception excep){};*/
      void search_actionPerformed(ActionEvent e) {
        int n = Integer.parseInt(JOptionPane.showInputDialog("Enter No:"));
        for (int i=0;i<v.size();i++)
          if (((A)v.elementAt(i)).getno()==n)
            txtno.setText(Integer.toString(((A)v.elementAt(i)).getno()));
            txtname.setText(((A)v.elementAt(i)).getname() );
            txtage.setText(Integer.toString(((A)v.elementAt(i)).getage()));
      public void fileOutput()
        try
          out = new ObjectOutputStream(new FileOutputStream("c:\\UserData.txt",true));
        }catch(Exception excep){};
      public void fileInput()
        try
          in = new ObjectInputStream(new FileInputStream("c:\\UserData.txt"));
        }catch(Exception excep){};
      void read_actionPerformed(ActionEvent e) {
      fileInput();
        try
          a = (A)in.readObject();
          txtno.setText(Integer.toString(a.getno()));
          txtname.setText(a.getname());
          txtage.setText(Integer.toString(a.getage()));
        }catch (Exception excep){};
    }

    //program which copies string data between vector and file
    import java.util.*;
    import java.io.*;
    class Util
    private Vector v;
    private FileReader filereader;
    private FileWriter filewriter;
    Util(String data[])throws Exception
      v=new Vector();
      for(String o:data)
        v.add(o);
    public void listData()throws Exception
      int size=v.size();
      for(int i=0;i<size;i++)
       System.out.println(v.get(i));
    public void copyToFile(String data,String fname)throws Exception
      filewriter =new FileWriter(fname);
      filewriter.write(data);
      filewriter.flush();
      System.out.println("Vector content copied into file..."+fname);
    public void copyFromFile(String fname)throws Exception
      filereader=new FileReader(fname);
      char fcont[]=new char[(int)new File(fname).length()];
      filereader.read(fcont,0,fcont.length);
      String temp=new String(fcont); 
      String fdata[]=temp.substring(1,temp.length()-1).split(",");
      for(String s:fdata)
        v.add(s.trim()); 
      System.out.println("File content copied into Vector...");
    public String getData()throws Exception
       return(v.toString());
    class TestUtil
    public static void main(String a[])throws Exception
      String arr[]={"siva","rama","krishna"};
      Util util=new Util(arr);
      System.out.println("before copy from file...");
      util.listData();
      String fname=System.getProperty("user.home")+"\\"+"vecdata";
      util.copyToFile(util.getData(),fname);
      util.copyFromFile(fname);
      System.out.println("after copy from file...");
      util.listData();
    }

  • Hello, I have two questions on time capsule  I can only have it on my external hd files and free up my internal memory to my mac  I can use an external hard drive, in my case a lacie rugged as shared memory for my two computers

    Hello, I have two questions on time capsule  I can only have it on my external hd files and free up my internal memory to my mac  I can use an external hard drive, in my case a lacie rugged as shared memory for my two computers

    I have a mackbook pro and an iMac if I buy a time capsule 2tb airport, I can use it with time machine and what would be the best way to use it.
    There is no particular setup required for TM.. both computers will create their own backup sparsebundle which is like a virtual disk.. Pondini explains the whole thing if you read the reference I gave you.
    and how to use time capsule airport whit other external hd to use my old lacie airport with the new time capsule
    Up to you.. you can plug the external drive into the TC and enjoy really slow file transfers or you can plug it into your computer and use it as external drive.. which is faster than the TC.. and TM can include it in the backup.
    Again everything is explained in the reference.. you are not reading it.

  • Catalogs, Missing Files, and Question Marks for Beginners

    Hello, fellow non-power-users. I just wanted to post something here that I've learned with my travails and travels using LightRoom 3. In the past, Adobe has paid me to write for them, and I'm a professional writer. So why am I doing this for free? Because I wish to heck I'd understood this stuff before I dove into LR. Somehow, even with reading a book on the program, I didn't really get it.
    1) Most of the people who are kind enough to post and help on Adobe support and other forums on the Interwebs are power users of Lightroom. The great thing is, they often know what they're talking about. The bad thing is, many of them don't understand what it's like to be a non-power-user who really has no intention of becoming a power user. Be very, very careful before you try to take their advice about any large issue that might have serious consequences for your photos.
    2) LR has about forty million ways to do things, so it can be overwhelming, and you may also receive lots of contradictory information about how to accomplish stuff. If you're like me---not a professional photographer, more a refugee from the annoying land of iPhoto who just needs a *little* more power and customization---you may have trouble streamlining, figuring out the few things you actually need the program to do for you. Try some introductory videos and tutorials, even books, but don't expect them to solve your real problems with the program.
    3) Before you begin, grasp a few concepts:
         a. When you're working in LR, you're working with a "catalog." It shows you images of your photos, but these aren't really your photos. Your actual photos are *files* that live on your computer somewhere. Think of it as a slideshow projected on a wall: you can see the photos on the wall, but they aren't the "real photo." If you walked up to the wall and painted on the projection of a slide, the "real photo" file would not be changed. What LR does is keep track of those wall paintings for you, so if you wanted to print up a version of that slide and include your brush strokes, LR could do that for you. The catalog is a type of database.
         b. So where are those real photos, those files? Probably all over your computer in different places. You may want to consolidate them all in one place before you start using Lightroom. Here's why: once Lightroom thinks your "real photo" is in a certain place, it doesn't want you to move the "real photo" file. Say you have a photo called that someone sent in email. You put it on your desktop. Now you are tempted to drag-n-drop it onto Lightroom. DO NOT DO IT. Because someday, you might want that photo to not clutter up your desktop. You'll drag it to another folder on your hard drive, and BOOM, now Lightroom cannot find the photo.
    You can't work on the photo from within Lightroom. You can't print it. Lightroom will show a question mark ? on its wall-projector slide of your photo file. Often when someone moves files on their computer, it's not a single file on a desktop. It's a bunch of things they are trying to organize. Adobe knows this, which is why they have a "find missing photos" command. They know you are likely to screw this up. The command will show you those missing files. You have to select them individually by hand and search your computer for them to relink. You can spend a lot of time relinking photos. It sucks. Really sucks.
         c. If you do need to move stuff, Lightroom does let you do it, but only from within the program. So, open up LR, and look in the left-hand column for an item called "Folders." (You will be in Library mode to make this happen.) You can move your "real photo" files around from within this area. It is a clunky process and an enormous pain in the butt.
         d. Rant time: For some reason, one of the most sophisticated and long-lived software companies in history, the developers that completely changed the worlds of art, design, photography, and publishing--you got it, Adobe--have not been able to solve this problem and chase down your real photo files if you moved them from within the Finder, the way you normally move files on a computer. Go figure. (Irrelevant note: I've been using their products since Pagemaker 1.0 and it's sort of astonishing that they've never solved this problem, in LR or InDesign or elsewhere. It's like publishing a magazine using Quark in 1995, rushing to find the messed-up links before you hand-carry your ZIP drive over to the printer. Hee hee.)
    4) Decide whether you want to divide your photos into a few separate catalogs, or whether you want one enormous catalog ("master catalog"). Then try not to change your mind.
    Here is my story:
    Summary: I started with multiple catalogs and regret merging them into one.
    I hired a photographer/supposedly-LR guy to set up my LR and he suggested multiple catalogs, each easily saveable (catalog AND its photos) to a single external hard drive. I only made two: one for family photos, one for a big art project. Whenever I asked questions online about using LR, everyone told me to combine all photos into one big master catalog. Eventually I did, and I regret it. As a non-power-user, I screwed up something in the merging process, and ended up with a lot of question-mark, missing-photo problems, and a bunch of duplicate photos to boot. What a waste of time.
    If you're not a pro, you probably don't need a gigantic single database to deal with. If you're someone who uses Dropbox or another non-Adobe cloud method to store and work with your photos, and you don't have unlimited storage, you may find it way more convenient to have a few different catalogs.
    Power users probably don't screw up the process of merging all their catalogs into one. Power users have, from what I've read online, many complicated ways of making a big master catalog work the way they want, say for working on small numbers of files while traveling with a laptop, and then getting that work into the giant master catalog when they get back home to their studios.
    But I am not a power user, and if you're reading this, you probably aren't a power user either. So perhaps my experience will be useful to you.
    5) Paying for plug-ins to help with all this nonsense.
    You can buy plug-ins that help you do things this application should already do by itself. For example, "Duplicate Finder" goes through and finds all the photos that you've accidentally imported more than once into your catalog. Then you can painstakingly go through, figure out which copy to keep, and delete them. Often, these "duplicate" photos are not duplicates of your "real photo" file. But at some point you moved your "real photo" file while you were tidying up your computer files, and later accidentally re-imported that photo into your LR catalog. Since LR doesn't follow your files around when you move them from within your computer/Finder, LR thinks it's a whole brand-new file. It's like your projector is projecting three images on the wall at the same time. You have to figure out which one to keep, which one will save your wall-painting changes, etc. And it is a huge pain in the butt.
    Note that you can click a box when importing photos, a box that says "Do not import suspected duplicates." This can be really helpful for avoiding duplicates in the first place. It is not, however, infallible.
    OK, I hope this helps someone somewhere. I'm going to go back to the horribly time-consuming task of relinking files and trying to make my brain work the way LR's brain works.

    Glad to help!
    Another good thing to do from time to time is to boot from your install CD, then choose "Disk Utility", then do a check (and repair, if necessary) of your boot disk.
    You can't verify or fix a disk you've started from, thus the need to boot from a CD. You can boot from a second hard disk to do this test if it has MacOS on it.

  • Photo Files and iPhoto Questions

    I have a few questions in relation to my actual picture files and when they are imported into iPhoto (on my mac).
    Intro: Let me catch you up on my situation, I have all my picture files (around 8000 of them!) on my time capsule; most of them are organized in their own folders (such as halloween 2011 and christmas 2010) but some of them are unsorted in their own folders (such as unsorted 2012 and moms cam). I've imported all these into iPhoto, the folders all appear as events, and I have applied faces and locations to almost all of them (about 85%). Now my questions:
    1: If I delete/move some pictures from my time capsule around the folders (so I move some picture from moms cam to halloween 2012 and thanksgiving 2012 folders), how do I sync this with iPhoto? (Ex. I have deleted some pictures from "my graduation" folder in my time capsule, but on the iphoto event for "my graduation", all the pics are there even the ones Ive deleted) Will I have to manually delete these from iphoto as well?
    Status: unanswered
    2: Is the data saved on the picture file? So If I were to delete the event from iPhoto, and re-import the folder, will all the faces and locations that Ive added on iPhoto still be saved? or would I have to manually add all the faces and locations again?
    Status: unanswered
    3: My main photo files are the files on my Time Capsule; If, by chance, iPhoto turns out to make its own file system of the photos I import, where would that location be? Are they individual files (such each pic as a .jpeg file) or is it something more like a single file with all the pictures and data?
    Status: unanswered

    1 - is the Time Capsule being used as an external hard drive or as a Time Machine backup drive - you must not use it as both
    2 - is the iPhoto preference to "copy imported items to the iPhoto library" is checked ( - a managed library - default and strongly recommended) or have you unchecked i (a referenced library - which it sound like you have - this is strongly not recomended)
    for your question 1, if you have a referenced library - iPhoto never does anything outside of its database - the iPhoto library - and it does not "sync" or watch external folders -  if you choose to manage the originals then you must do that  - one of the many reasons that a referenced library is not recommended is that improting is more difficult and deleting is more difficult
    for question 2, if you delete photos from iPhoto then they and all of their associated data is gone - if you reimport the "same" photo, its is totally new to iPhoto - you are starting from scratch with it
    for your question 3 - this is not a matter of chance - you either have a referenced library or a managed library which you choose - and in a referenced library the originals are not copied to the iPhoto library - for a managed library they are and are stored in the masters or originals folder in iPhoto depending on your version of iPhoto which you do not share as bit for bit copies of the originals
    LN

  • Question about reading a sequential file and using in an array

    I seem to be having some trouble reading data from a simple text file, and then calling that information to populate a text field. I think I have the reader class set up properly, but when a menu selection is made that calls for the data, I am not sure how to receive the data. Below is the reader class, and then the code from my last program that I need to modify to call on the reader class.
    public void getRates(){
              try{
                 ArrayList<String> InterestRates = new ArrayList<String>();
                 BufferedReader inputfile = new BufferedReader(new FileReader("rates.txt"));
                 String data;
                 while ((data = inputfile.readLine()) != null){
                 //System.out.println(data);
                 InterestRates.add(data);
                 rates = new double[InterestRates.size()];
                 for (int x = 0; x < rates.length; ++x){
                     rates[x] = Double.parseDouble(InterestRates.get(x));
           inputfile.close();
           catch(Exception ec)
    //here is the old code that I need to change
    //I need to modify the rateLbl.setText("" + rates[1]); to call from the reader class
    private void mnu15yrsActionPerformed(java.awt.event.ActionEvent evt) {
            termLbl.setText("" + iTerms[1]);
              rateLbl.setText("" + rates[1]);

    from the getRates function your InterestRates ArrayList is declared within that function, so it will not be accesible from outside of it, if you declare it outside then you can modify in the function and have it accessible from another function.
    private ArrayList<String> InterestRates = new ArrayList<String>();
    public void getRates(){
              try{
                 BufferedReader inputfile = new BufferedReader(new FileReader("rates.txt"));
                 String data;
                 while ((data = inputfile.readLine()) != null){
                 //System.out.println(data);
                 InterestRates.add(data);
                 rates = new double[InterestRates.size()];
                 for (int x = 0; x < rates.length; ++x){
                     rates[x] = Double.parseDouble(InterestRates.get(x));
           inputfile.close();
           catch(Exception ec)
         }

Maybe you are looking for

  • Photoshop CS5 Crashing Everytime Try open an image

    Today I rebooted after upgrading to OS 10.6.4. I also ran monolingual to cleanup all languages except english. Everytime I open CS5 now as soon as I try to open an image it crashes. I've disable open gl and the same thing occurs. The report is gives

  • Scripts :EMail - gettiing 3 page data into 2 pages

    Hi all, I have created the layout using sap script for sales order and  when i see the print preview of sales order i can able to see th 3 pages in the layout in the NACE i have configured it to EMAIL so far i am getting email as per the design. Prob

  • BSP pages no logged out

    We have several BSP pages on our Portal.  When a user logs out and does not close the browser, the BSP sessions are retained.  The next user picks up the user id of the person who just logged out.  Example - user A logs out of the portal.  User B the

  • Spatial operator issue

    Hallo, I have a general question. I am using a spatial operator. There it is a general rule that the first parameter must come from a indexed table and the second need not to be indexed. As far as good. The other rule is that the first parameter shou

  • How to Uninstall xcode Tools?

    I installed Gimp, and was looking for X11, and assumed it was in the xcode tools package on the Apple OSX install disc. So I installed the xcode tools, and got the 'successfully installed' notice. But then found out X11 is not in xcode tools! Eventua