How to retrieve arrays from a file.

If i were to save 5 arrays to a file like this.....
DataOutputStream output;
     DataInputStream input;
     Date today = new Date();
     String filename = "phonebook";
private String name[] = {""};
     private String surname[] = {""};
     private String home[] = {""};
     private String work[] = {""};
     private String cell[] = {""};
     try
               output = new DataOutputStream(new FileOutputStream(filename));
          catch(IOException io)
               JOptionPane.showMessageDialog(null,"This program could not create a storage location. Please check the disk drive and the tun the program again.","Error",JOptionPane.ERROR_MESSAGE);
               System.exit(1);
public void save()
          try
               for(int i=0; i < name.length; i++)
                    output.writeUTF(name);
                    output.writeUTF(surname[i]);
                    output.writeUTF(work[i]);
                    output.writeUTF(home[i]);
                    output.writeUTF(cell[i]);
               JOptionPane.showMessageDialog(null,"Data succesfully saved to file.","Information message",JOptionPane.INFORMATION_MESSAGE);
          catch(IOException io)
               System.exit(1);
     }And then I want to use them again on my startup. How would I go about initialising them back into thier origianl arrays. What i mean is I want the arrays to contain theier previous saved values. Is this possible.
I tried to do it like this but it wont work. I get no errors. It just wont return and strings at all.try
               input = new DataInputStream(new FileInputStream(filename));
          catch(IOException io)
               JOptionPane.showMessageDialog(null,"Could not find the correct file to read data from.","Error",JOptionPane.ERROR_MESSAGE);
          try
               for(int i=0; i< name.length; i++)
                    name[i]=input.readUTF();
                    surname[i]=input.readUTF();
                    work[i]=input.readUTF();
                    home[i]=input.readUTF();
          cell[i]=input.readUTF();
          catch(IOException io)
          }Or is it better to create a seperate file for each array?
Edited by: Yucca on Mar 23, 2008 2:24 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Any help here please.
Edited by: Yucca on Mar 23, 2008 6:34 PM

Similar Messages

  • How to retrieve value from xml file

    hi all,
    can somebody pls tell me how to retrieve value from xml file using SAXParser.
    I want to retrieve value of only one tag and have to perform some validation with that value.
    it's urgent .
    pls help me out
    thnx in adv.
    ritu

    hi shanu,
    the pbm is solved, now i m able to access XXX no. in action class & i m able to validate it. The only thing which i want to know is it ok to declare static ArrayList as i have done in this code. i mean will it affect the performance or functionality of the system.
    pls have a look at the following code snippet.
    public class XMLValidator {
    static ArrayList strXXX = new ArrayList();
    public void validate(){
    factory.setValidating(true);
    parser = factory.newSAXParser();
    //all factory code is here only
    parser.parse(xmlURI, new XMLErrorHandler());     
    public void setXXX(String pstrXXX){          
    strUpn.add(pstrXXX);
    public ArrayList getXXX(){
    return strXXX;
    class XMLErrorHandler extends DefaultHandler {
    String tagName = "";
    String tagValue = "";
    String applicationRefNo = "";
    String XXXValue ="";
    String XXXNo = "";          
    XMLValidator objXmlValidator = new XMLValidator();
    public void startElement(String uri, String name, String qName, Attributes atts) {
    tagName = qName;
    public void characters(char ch[], int start, int length) {
    if ("Reference".equals(tagName)) {
    tagValue = new String(ch, start, length).trim();
    if (tagValue.length() > 0) {
    RefNo = new String(ch, start, length);
    if ("XXX".equals(tagName)) {
    XXXValue = new String(ch, start, length).trim();
    if (XXXValue.length() > 0) {
    XXXNo = new String(ch, start, length);
    public void endElement(String uri, String localName, String qName) throws SAXException {                    
    if(qName.equalsIgnoreCase("XXX")) {     
    objXmlValidator.setXXX(XXXNo);
    thnx & Regards,
    ritu

  • How to retrieve rows from .csv file

    Hi
    I need to retrieve rows from .csv file , anybody's kind support is greatly appreciated.
    Thanks in advance.
    Khiz_eng

    a .csv file is just a comma delimited text file. each row contains data separated by a comma. To read this information in, do as Hartmut suggested to your earlier post on this exact topic. "I would read that file with a FileReader / BufferedReader and parse each line with StringTokenizer. This would be quite the same like working through a result set." For more info on how to read text files, see any java book or browse through the i/o tutorial.
    Jamie

  • How to retrieve image from XML  file

    Hi All,
    I am new to XML. So any best guidance is appreciated.
    The application requirement is to display image retrived from uploaded xml file in file upload section of our application. And store that image in database.
    In my XML file , images & strings & numbers & booleans are there . I am able to save everything in database except images .
    I am using JSF, Seam & Hibernate combination. In my Hibernate entity class i took BLOB datatype for image.
    I am using following tags in my Xhtml file to display image
    <s:graphicImage value="#{hibernateentitybean.picBlobtype}" height="200" width="200">
    <s:transformImageSize width="200" height="200" />
    <s:transformImageType contentType="image/jpeg"/>
    But image is not displayed in Xhtml file
    I am using org.w3c.dom.Document for retrieving node name & corresponding value in that node in XML file.
    I am getting code like below for Image when i am logging all values from XML files in my bean class .
    x0lGQRQAAAABAAAAAAAAAFJHAQARAAAAVwBhAHQAZQByACAAbABpAGwAaQBlAHMALgBqAHAAZwAAAP/Y/+AAEEpGSUYAAQIBAGAAYAAA/+0YLl
    I want to convert this value to image. So i can convert image to bytes and store in BLOB.
    Can anyone guide me ? or any other approach .
    Thanks in advance for any reply.
    Regards,
    Naresh

    Dan_Koldyr wrote:
    agree, it's really odd. Just reread OP and it says:
    NareshDharmiVatsal  wrote:
    want to convert this value to image. In any case it doesn't get worth then another single code line:
    final String cdata = "x0lGQRQAAAABAAAAAAAAAFJHAQARAAAAVwBhAHQAZQByACAAbABpAGwAaQBlAHMALgBqAHAAZwAAAP/Y/+AAEEpGSUYAAQIBAGAAYAAA/+0YLl";
    final sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
    final byte[] data = decoder.decodeBuffer(cdata);
    Blob blob = new SerialBlob(data);//or what ever other DB-specific blob implementaiton Did i answered original question? Any more comments to my first replay?I can comment on this latest code. The package sun.misc is private to Sun (Oracle now of course). It is undocumented and may change or be removed altogether in a future release. There is a good free open source Base64 decoder in the Jakarta Commons Codec library.

  • How to read arrays from a file

    hi i was curious if i have a data file something like this
    34 12 10 5 4 3
    23 12 11 19 18
    42 32 23 12 11
    how can i read this data file and lines into three different arrays
    for example myArray1 should contain the first line which is 34 12 10 5 4 3 i am having alot of hard time.
         public static void main(String[] args) throws IOException
              int[] myArray = new int[10];
              //int[] myArray1 = new int[10];
              Scanner s = null;
              Tester2 test = new Tester2();
              try
                   s = new Scanner(
                        new BufferedReader (new FileReader("numbers.txt")));
                        while(s.hasNext())
                             if(s.hasNextInt())
                                  for(int i=0; i<myArray.length; i++)
                                  myArray[i] = s.nextInt();
                                  System.out.print(" "+myArray);
              finally
              { s.close();
    this things prints me the whole array

    lol you stupid fookks.
       try{
            BufferedReader bf=new BufferedReader(new FileReader("program1.txt"));
            String s=bf.readLine();
                String s1[]=s.split("\\s");
                int[] array1=new int[s1.length];
                for(int i=0;i<s1.length;i++)
                  array1=Integer.parseInt(s1[i]);
    s=bf.readLine();
    String s2[]=s.split("\\s");
    int[] array2=new int[s2.length];
    for(int i=0;i<s2.length;i++)
    array2[i]=Integer.parseInt(s2[i]);
    s=bf.readLine();
    String s3[]=s.split("\\s");
    int[] array3=new int[s3.length];
    for(int i=0;i<s3.length;i++)
    array3[i]=Integer.parseInt(s3[i]);
    kiss my asian a$$ you all think i am a dumb fok well you know what you have freakin attitude problems. i can do it on my own also you all dumb senior foks. i asked for help warnerja not for your stupid a$$ comments fok yuou.... i am not a freakin newbie just new to this file. stuff. thats all all i was doing was asking for help

  • How to retrieve data from xml file into obiee reports

    Hi all,
    I've got a situation here. A xml file is stored as blob in oracle database table. Now i need to retrieve data/info from that xml file into obiee reports. How am i supposed to proceed with this ?

    I will go for a table function:
    http://gerardnico.com/wiki/database/oracle/table_function
    In two words, you can create a function that behave as a table. Then you create a function to pick up your xml, you parse it and you send back the rows.
    I know that Oracle has also a library for XML files but I never use it until now.
    Success
    Nico

  • How to retrieve images from the file system in Portal Forms?

    Portal 3.0.9.8.0
    In a Portal form , there is a field named ID wherein a value is entered. Say the value entered is 5 , how can we get the image named 5.jpg
    from C:/images/ folder and get it displayed in the form ? The images are not stored in the database . Depending on the ID field value , we
    have to retrieve the image.
    Thanks .
    Neeti.

    Hi Neeti,
    This is what I did :-
    Steps:-
    1> I created a procedure named get_image in the application schema as :-
    create or replace procedure get_image
    p_id in integer default 1
    is
    begin
    htp.p('Image Id='||nvl(to_char(p_id),'No Image Id'));
    htp.br;
    if p_id is not null then
    htp.p('<img src="C:\images\'||p_id||'.jpg">');
    end if;
    end get_image;
    2> Created a form on the procedure get_image.
    3> Run the form and for p_id field, enter the image id, and click on Submit - the image will be displayed.
    Hope this helps.

  • HT1766 how to retrieve the back up files from the itunes

    how to retrieve the back up files from the itunes

    What are you trying to do...extract data from your backup? If so, you need something like this:
    http://www.iphonebackupextractor.com/

  • How to retrieve info from a MacOs Standard floppy?

    How can I retrieve information from a MacOs Standard formatted floppy disk on Snow Lion?
    I have this collection of old floppy disks that were formatted as MacOs Standard format back in the days. They do hold some files which I'd like to backup on a backup drive.
    But, Snow Lion does not read MacOs Standard formatted disks apparently.
    So, does anyone know how to retrieve information from MacOs Standard formatted floppy disks?
    Thank you!

    This what I see in ML with my old SmartDisk VST (model# FDUSB-M) floppy drive:
    Interesting observations:
    1. I was able to add and remove files to the disk.
    2. I was not able to erase the disk with Disk Utility. It returned an error.
    3. Disk Utility did not offer the HFS+ format option, only FAT32 and ExFAT.
    4. I could only find 1 floppy in my house so it could be partially defective.

  • How to parse contents from XML file in Java

    Hi All,
    I have a scenario like this . I have one xml file with key value pairs of ( name , URL ) . I have retrieved contents from XML file , now I want to parse these contents and store in a bean object.
    How to parse Contents of XML file??
    Thanks in advance,
    Rajendra.

    Hi All,
    I have a scenario like this . I have one xml file with key value pairs of ( name , URL ) . I have retrieved contents from XML file , now I want to parse these contents and store in a bean object.
    How to parse Contents of XML file??
    Thanks in advance,
    Rajendra.

  • How to retrieve data from excel sheet

    Hi,
    How to retrieve data from excel sheet into a java file.

    janu05 wrote:
    If we append a $ in the end of the table name it is showing an error saying "invalid name,should not contain any invalid character or punctuation"Great, I'm very happy for you.
    Unless that was a question. In which case you might what to tell us a little more.
    Like which API you are using (assuming we are still on "reading an Excel sheet".

  • How to retrieve data from inside the folders in SharePoint SSRS

    Hi ,
    How to get the data from inside the folders and subfolders.
    How can I do that.
    https://social.msdn.microsoft.com/Forums/en-US/15451351-4ee2-428c-a0b7-135810e4cbfa/action?threadDisplayName=ssrs-reports-sharepoint-list-datasource-how-to-retrieve-items-from-subfolders
    Here the information is not given.
    Regards
    Vinod

    Hi Vinodaggarwal87,
    According to your description, you want to retrieve data from sharepoint list in a sub folder. Right?
    In this scenario, we should select the XML data source type and in the connection string provide the
    List.asmx service URL when creating data source. Then we need to use the List web Service and specify "recursive" for ViewAttribute in Lists.asmx. For detail steps, please refer to the links below:
    Generate SSRS report on SharePoint List with folders using List Service.
    SSRS: how to specify ViewAttributes when creating a report against a SharePoint's list
    If you want to set the ViewAttribute on CAML query level. You need add the view tag outside of query tag:
    <View Scope="RecursiveAll">
        <Query>
            <Where>...</Where>
        </Query>
    </View>
    Reference:
    View Element (List)
    ViewAttributes Recursive Scope not working SharePoint 2013 CAML Query to fetch all files from document library recursively
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • How to read data from a file that was formatted by excel?

    Hi everyone, I'm familiar with java.io and the ability to read from files, can anyone tell me how to read data from a file that was formatted by excel? Or at least give me some web references so that I can learn about it?

    http://jakarta.apache.org/poi/hssf/index.html
    HSSF stands for Horrible Spreadsheet Format, but it still works!

  • HELP!!!!   How to read data from a file at time to time?

    i store temporary string data in a file(the data changes always), and i need to read the data in the file from time to time, so how can i read from the file like every 5 seconds?

    Please i need your help mr. noahw. i have a timer called timer1 inside that timer i am starting a thread to read the data in a file to me, then i have another timer timer 2 in which it takes the data already read from timer 1 and draws them on a GUI. the problem with me is that, i am unable to set a correct time for each of the two timers such that, every time timer one executes that is a new data is generated i need to draw only one figure coreesponding to those data, then when a new set of data is read i need to draw another figure based on the new data read, please help me with this becasue i need it urgently, this is my email, [email protected], and i can offer this reply as many points as you want if this helps you to help me, i am counting on you.

  • How to remove Unicode from XML file

    I get following error when unmarshal xml:
    [java] org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x15) was found in the element content of the document.
    Anyone know how to remove Unicode from xml file? Can I remove the unicode by rebuild the file?
    Thanks

    These sort of error usually occur when you're using a different character encoding to read the file than the one you wrote it with. Perhaps if you were to post the problem section of the file and/or the code that created it in the first place.

Maybe you are looking for

  • Is it possible to recover lost data from an iPhone 4 iOS 5

    Hello, I recently upgraded my iphone from iOS 4.2 to 5.0, and in the process of restoring my iphone, my photos and some other settings (some email accounts and phone number "favorites") were not restored.  I'm very upset about the pictures....I've lo

  • I have 2 icloud accounts - how do I combine them?

    I currently have 2 icloud accounts and I am looking for a way to combine them into one account.  Can anyone help me with this?

  • I can't import mp4 files onto itunes

    i tried several times to import my mp4 files onto itunes but failed everytime. how to overcome this?

  • Basic details abt report painter

    hi, I am new to report painter, need to know some basic details abt report painter. And one example along with it Regards, Reni

  • Plug-ins not be showed in the list

    after i had reinstalled "ik multimedia reverb...",it disappeared in the list of plug-ins in Logic pro 9.however,whatever how many times i rescan the audio unit manager,it doesn't work:still can't find the plug-ins in the list....but in "soundtrack" a