11 Replies Latest reply: Apr 19, 2009 1:33 PM by 843789 RSS

    IO write problem

    843789
      I'm getting the error

      C:\Documents and Settings\User\My Documents\UOP\JAVAII\Class_Library\DennisWK5.java:185: cannot find symbol
      symbol : method writeUTF(java.lang.String[])
      location: class java.io.OutputStream ostream.writeUTF(data[1]);

      I'm not sure what's going on any help would be appreciated
      public void writeFile(String[] data[][])
      {
      File graphFile = new File("graphdata.dat");
      OutputStream ostream;
      
      try
      {
      ostream = new DataOutputStream(new
      BufferedOutputStream(new FileOutputStream(graphFile)));
      
      }
      catch
      (IOException e)
      {
      JOptionPane.showMessageDialog(null,"File not opened");
      }
      
      for (int i=0; i < data.length; i++)
      {
      /*line 185*/ ostream.writeUTF(data[1]);
      ostream.writeUTF(data[i][2]);
      }
      }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
        • 1. Re: IO write problem
          baftos
          public void writeFile(String[] data[][])
          data is a 3-dimensional String array. So you are trying to call writeUTF( String[] ), which does not exist.
          Probably the mistake is some extra []?
          • 2. Re: IO write problem
            843789
            So any advice how I would write to a file the contents of my object[] data[][] multi-dimensional array. I'm not have any luck here. It doesn't seem like it would be a bunch of code to write, but I'm just not having any success here.
            public void writeFile (object[] data[][]) 
            {
            // Java's little miracle here
            }
            and the happy ending of all that lovely object data written to a file. The object data could be converted to a string if needed. Anyone feeling generous enough to show me how it's done?

            • 3. Re: IO write problem
              843789
              This may not be the answer you are looking for, but a String[][][] -- an array of arrays of arrays of Strings -- smells bad. In such cases your code would be improved by defining more and better classes and lessening your addiction to arrays.

              But if you gotta:
              for(String[][] matrix : data) {
                  for(String[] vector : matrix) {
                      for(String s : vector) {
                          ostream.writeUTF(s);
                      }
                  }
              }
              If the length of any of those arrays is not known in advance, you will need to write it, too, so that the receiver can reconstruct this mess.
              • 4. Re: IO write problem
                843789
                No I didn't mean to have String[] should have been String data[][], but it still gives me an error.

                C:\Documents and Settings\User\My Documents\UOP\JAVAII\Class_Library\DennisWK5.java:178: cannot find symbol
                symbol : method writeUTF(java.lang.String)
                location: class java.io.OutputStream
                                    ostream.writeUTF(data[1]);
                                    ^
                     public void writeFile(String data[][])
                     {
                          File graphFile = new File("graphdata.dat");
                          OutputStream ostream;
                
                          try
                          {
                               ostream = new DataOutputStream(new
                            BufferedOutputStream(new FileOutputStream(graphFile)));
                
                            for (int i=0; i < data.length; i++)
                               {
                                    ostream.writeUTF(data[1]);
                                    ostream.writeUTF(data[i][2]);
                               }

                          }
                          catch
                          (IOException e)
                          {
                               JOptionPane.showMessageDialog(null,"File not opened");
                          }
                          finally
                          {
                               ostream.close();
                          }
                     }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                • 5. Re: IO write problem
                  843789
                  Declare:
                  DataOutputStream ostream;
                  not
                  OutputStream ostream;
                  because you want to use D.O.S. methods like writeUTF, not?
                  • 6. Re: IO write problem
                    baftos
                              OutputStream ostream;
                    If you declare ostream like this, you can only use OutputStream methods.
                    DataOutputStream ostream; // I can use DataOutputStream methods!
                    • 7. Re: IO write problem
                      843789
                      That is because you dont have access to that method in the way you write your code.

                      You only have access to the methods given by the abstract class OutputStream.

                      If you want access to the method writeUTF, you will need to create an DataOutputStream object.

                      Like this:
                                DataOutputStream ostream;
                       
                                try
                                {
                                     ostream = new DataOutputStream(new
                                  BufferedOutputStream(new FileOutputStream(graphFile)));
                      • 8. Re: IO write problem
                        843789
                        lol, im sooo slow and typing my replys..
                        • 9. Re: IO write problem
                          843789
                          That was the problem, thank you.
                          • 10. Re: IO write problem
                            843789
                            same problem, thank you


                            [Win Roulette|http://www.winroulettebot.com]
                            [Win Poker|http://www.winpokerbot.com]
                            [Win Casino|http://www.win500aday.com]
                            [Win BlackJack|http://www.winblackjackbot.com]

                            Edited by: win500aday on Apr 19, 2009 5:47 PM
                            • 11. Re: IO write problem
                              843789
                              AR