Something wrong in writing a new file

Hello,
I'm new to Java and I seem to have trouble in writing a string to a file.
Here is the code:
void show_seat()
          try
               BufferedWriter tr=new BufferedWriter(new FileWriter("try.txt"));
               for(int i=0;i<5;i++)
                    for(int j=0;j<4;j++)
                         String t=fclass[i][j];
                         tr.write(t);
                         x.print(t);
                    x.println("");
          catch(IOException e)
               System.out.println("File Not found");
     }My array is perfect and it is printing out the correct output. But for some reason it just doesn't write it into the file.
Also could someone tell me how to close a file properly!!

You need to flush the writer. Close()ing it willdo
that. The close() call should be in a finallyblock.
Well I'm trying to close the file by saying
tr.close();
But is says it cannot be resolvedBecause you declared it inside the try block.
BufferedWriter br = null;
try {
   br = ...
   br.write or whatever
catch (...) {
  Note that just printing defeats the purpose of catching.
  You should handle it or not catch it in the first place.
  For a simple exercise like this it's okay though.
finally {
  if (br != null) {
    try {
      br.close();
    catch (Throwable th) {
      Here it's correct to do nothing at all or just log it.
} >
And Also I haven't learnt about how to flush the
Buffer in class.Closing it will flush it.

Similar Messages

  • FCPX 10.1.3 something wrong with audio in .MTS file

    Hi,
    I've just update from FCPX 10.1.1 to 10.1.3.
    I've reported something wrong when i import .MTS files (from my Sony VG30). There are lot of audio paradise. If i listen to the file on another computer there are no problem, but when it was imported in FCPX, it appears. Also with optimised and proxy files.
    If i export a project, the parasite still present.
    If i first rewrap the .MTS files with ClipWrap, then the file imported in FCPX don't have any problem.
    For sure, i don't have that kind of problem in FCPX 10.1.1
    Some other user with that ?

    Yep, i know that method is better, anyway i can't always do that cause i also received directly .MTS file and not the physical SD Card, or should backup the files on a server before import it on my Mac and start the new project.
    I've checkup an imported file i've made with 10.1.1 and played in 10.1.3 and there aren't any bug files, so it's seems to be linked to 10.1.2 or 10.1.3 update : (

  • Is there something wrong with my brand new rMPB battery?

    I recently got my new rMBP and I am not sure if it has some sort of defective battery or not. I feel as though the battery discharges far too quickly, often going from 96% charge ("8:27 remaining") to 87% charge ("5:08 remaining) or so in a matter of thirty minutes, perhaps sometimes more. I wasn't sure if this was due to having Mavericks since I have read that there have been a lot of cases where Mavericks has been responsible for short battery lives, or something of the sort.
    I am sure that Chrome is responsible for the majority of the fast discharging of the battery, but  find it hard to believe that it would take up so much energy so fast.
    On a side note, I would like to know if there is a "better" way to charge the battery? Is it bad to have it plugged in the whole time? Should I only begin to charge it once it reaches 20% charge left or only charge it up to 80% charge to avoid overcharging? These are just some things I have read or heard here and there.

    DanielGiron wrote:
    I recently got my new rMBP and I am not sure if it has some sort of defective battery or not. I feel as though the battery discharges far too quickly, often going from 96% charge ("8:27 remaining") to 87% charge ("5:08 remaining) or so in a matter of thirty minutes, perhaps sometimes more. I wasn't sure if this was due to having Mavericks since I have read that there have been a lot of cases where Mavericks has been responsible for short battery lives, or something of the sort.
    I am sure that Chrome is responsible for the majority of the fast discharging of the battery, but  find it hard to believe that it would take up so much energy so fast.
    I would contact AppleCare and see what they have to say (90 days free phone support).
    On a side note, I would like to know if there is a "better" way to charge the battery? Is it bad to have it plugged in the whole time? Should I only begin to charge it once it reaches 20% charge left or only charge it up to 80% charge to avoid overcharging? These are just some things I have read or heard here and there.
    The info you're reading refers to older battery models. For current batts, you can charge them as often as you like; the only thing you don't want to do is let it sit for a year and go completely dead (this is not the same as letting it run down while you're using it until your MBP goes to sleep, that's fine).

  • Writing a new file in non-existent directory

    I've written a program that will read files from one area and write them to another. It works great when the directory structure is already in place, but when I try to write the file in a directory that doesn't exist then problems occur. I was just wondering if there was some way of making it create the directory for me or do I have to parse the string and create the directories by hand? Thanks,
    Dave Johansen

    There's also a File.mkdirs() that will create any non-existent parent directories.

  • I am new to Final Cut Express and don't understand why I am unable to drag transitions into Canvas? Something wrong in my setup? It's not the overlays they are "on" so can anyone advise me please?

    I am new to Final Cut Express and don't understand why I am unable to drag transitions into Canvas? Something wrong in my setup? It's not the overlays they are "on" so can anyone advise me please, by the way the "L" doesn't appear in the bottom left hand corner either? and by the way how can I get rid of that irritating Blue badge saying "AutoFill your contact details" all mine are in "address book" already!

    You can't drag a transition into the canvas. If you're dragginmg a transition from the effects tab you drag it between the edit point of two clips in the timeline.
    Make sure show edit overlays is turned on in the Canvas view popup.

  • I have backed up my old phone to itunes, however, when I try to restore data to new phone it is saying the password is incorrect but I can get into my itunes account with my password so I am doing something wrong?

    I have backed up my old phone to itunes, however, when I try to restore data to my new phone it is saying the password is incorrect but I can get into my itunes account with my password so I am doing something wrong?

    I'm having this EXACT same problem with my iPhone 4, and I have the same computer stats (I have a Samsung Series 7)

  • After creating a new slideshow I export it with the  setting HD 1080p it is then saved as a .mov i then create a dvd in idvd and the quality is not  as good as the original photo's when viewed on the monitor or a TV, am i doing something wrong?

    After creating a new slideshow I export it with the  setting HD 1080p it is then saved as a .mov i then create a dvd in idvd and the quality is not  as good as the original photo's when viewed on the monitor or a TV, am i doing something wrong?

    DVD's are only 640 x 480 (interlaced), so yes, the quality is not nearly as good.  You should probably create your .mov in DV format to best match the DVD format

  • "The file 'Acknowledgements.rtf' cannot be installed because the file cannot be found in the cabinet file 'iTunes.cab'.  Is there something wrong with the latest installer? (11.3.1)

    Getting error message as shown: "The file 'Acknowledgements.rtf' cannot be installed because the file cannot be found in the cabinet file 'iTunes.cab'.  Is there something wrong with the latest installer? (11.3.1)

    Installs fine for me, so I'd guess you got an incomplete or corrupt download. See the Further Information area of Troubleshooting issues with iTunes for Windows updates for direct links and download a fresh copy of the installer.
    tt2

  • I'm doing something wrong when I try to create a file.

    I'm working with binary files, trying to do a log file and I'm having this error
    java.io.FileNotFoundException: log.dat (No such file or directory)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.<init>(FileInputStream.java:106)
         at Servidor.XServer.log(XServer.java:186)
         at Servidor.XServer$nwc$readLine.run(XServer.java:312)This is because the file is not being created, but I don't know why, here is my code, where I try to create it.
         /// ANADIR EVENTOS AL ARCHIVO LOG // ADD EVENTS TO LOG FILE
         int log(String arg[], String ip , String voto){
              File file = null;
             if (file == null) {
                 System.out.println ("Default: log.dat");       
                 file = new File ("log.dat");     //    why it isn't creating the file?
             // Now write the data to the file.
             try{
                  FileInputStream file_input = new FileInputStream (file);
                 DataInputStream data_in    = new DataInputStream (file_input);
                 String iptmp ="";  // ip tmp
                 String vot1=null;          // vot 1er lugar tmp
                 String vot2=null;        // vot 2do lugar
                 int itmp=0;          // intentos tmp
                 while(true){
                    try{
                      iptmp= data_in.readUTF();
                      vot1= data_in.readUTF();
                      vot2=data_in.readUTF();
                      itmp=data_in.readInt();
                 DataOutputStream data_out = new DataOutputStream (new FileOutputStream (file));
                 voto=(voto.substring(0, 1)+chart.get(Integer.parseInt(voto.substring(1, voto.length()))));
                           // SI EL IP YA VOTO POR EL PRIMER EQUIPO (ERROR EN VOTO)
                        if (iptmp.equalsIgnoreCase(ip) && vot1!=null && voto.startsWith("1")){
                             data_out.writeInt(itmp+1);
                             return(-1);
                        // SI EL IP YA VOTO POR EL SEGUNDO EQUIPO (ERROR EN VOTO)
                        if (iptmp.equalsIgnoreCase(ip) && vot2!=null && voto.startsWith("2")){
                             data_out.writeInt(itmp+1);
                             return(-1);
                        // SI UN IP NO HA VOTADO POR EL PRIMER LUGAR     
                      if (iptmp.equalsIgnoreCase(ip) && vot1==null && voto.startsWith("1")){
                         data_out.writeChars(ip);  // ip
                         data_out.writeChars(voto);   // voto por primer lugar
                         data_out.writeInt(itmp); // intentos de votos
                         // SI UN IP NO HA VOTADO POR EL SEGUNDO LUGAR
                      if(iptmp.equalsIgnoreCase(ip) && vot2==null && voto.startsWith("2")){     
                         data_out.writeChars(ip);  // ip
                         data_out.writeChars(voto);   // voto por segundo lugar
                         data_out.writeInt(itmp); // intentos de votos
                      data_out.close();
                 }catch (EOFException eof) {
                             System.out.println ("End of File");
                             break;
                      data_in.close();
             } catch (IOException e) {
                   e.printStackTrace();
              return 0;
         }Would you help me out with this? I don't see what is wrong I'm following an example from the oracle / java tutorial and I cant see what is different

    I´m not sure if Im understanding what you´re saying... If you dont describe the path, then the file will be created in the project folder, right?
    check this program out
    it doesnt specifies a path but if you try run it the file will be created in the project folder. ¨
    import java.io.*;
    import java.util.*;
    /**  Write a primitive type data array to a binary file.**/
    public class BinOutputFileApp
      public static void main (String arg[]) {
        Random ran = new Random ();
        // Create an integer array and a double array.
        int    [] i_data = new int[15];
        double [] d_data = new double[15];
        // and fill them
        for  (int i=0; i < i_data.length; i++) {
          i_data[i] = i;
          d_data[i] = ran.nextDouble () * 10.0;
        File file = null;
        // Get the output file name from the argument line.
        if (arg.length > 0) file = new File (arg[0]);
        // or use a default file name
        if (file == null) {
            System.out.println ("Default: numerical.dat");
            file = new File ("numerical.dat");
        // Now write the data array to the file.
        try {
          // Create an output stream to the file.
          FileOutputStream file_output = new FileOutputStream (file);
          // Wrap the FileOutputStream with a DataOutputStream
          DataOutputStream data_out = new DataOutputStream (file_output);
          // Write the data to the file in an integer/double pair
          for (int i=0; i < i_data.length; i++) {
              data_out.writeInt (i_data);
    data_out.writeDouble (d_data[i]);
    // Close file when finished with it..
    file_output.close ();
    catch (IOException e) {
    System.out.println ("IO exception = " + e );
    } // main
    } // class BinOutputFileApp

  • My New ipad3, when i click onthe camera app, the front camera works but the other camera only shows a black screen ! Is there something wrong with my iPad ?

    My New ipad3, when i click onthe camera app, the front camera works but the other camera only shows a black screen ! Is there something wrong with my iPad ?

    Try a Reset [Hold the Home and Sleep/Wake buttons down together for 10 seconds or so (until the Apple logo appears) and then release. When the screen goes blank power On again in the normal way.] It is absolutely/appsolutely safe!

  • I am trying to activate new itunes card. I am getting error message: The code you have entered has not been properly activated. Does this mean the store did something wrong or me?

    I am trying to activate new itunes card. I am getting error message: The code you have entered has not been properly activated. Does this mean the store did something wrong or me?

    Yes, the store didn't properly activate the card. If the store is nearly then you could try going back and asking them to do so, if it isn't (or if they can't/won't help) then try contacting iTunes Support (you will probably need to give them images of the front and back of the card, and possibly its receipt) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then iTunes Cards And Codes

  • How to insert new line char while writing bytes into file

    Hello Sir,
    Is it possible to insert the new line character in set of String variables and stored them into bytearray ,then finally write into File?
    This is the sample code which i tried:
                 File f = new File(messagesDir,"msg" + msgnum + ".txt");
                 FileOutputStream fout = new FileOutputStream(f);
                    String fromString = "From:    "+msg.getFrom()+"\n";
                    String toString = "To:     "+msg.getTo()+"\n";
                    String dateString = "Sent:    "+msg.getDate()+"\n";
                      String msgString =msg.getBody()+"\n";
                    String finalString=fromString+toString+dateString+msgString;
                    byte[] msgBytes = finalString.getBytes();
                    fout.write(msgBytes);
                 fout.close();in the above code , i tried to add the new line as "\n" in end of each string. but when i look into the generated files msg1.txt , it contains some junk char [] .
    please provide me the help
    regards
    venki

    but it has still shown the the junk char, its not able
    to create the new line in the created file i am afraid
    how am i going to get the solution?:(Do not be afraid dear sir. You are obviously using a windows operating system or a mac operating system. On windows a newline is "\r\n" not '\n', and on a mac a newline is '\r', not '\n'. If you make that correction, dear sir, your program will work.
    However, there is a better way. First, you probably want to buffer your output if you are going to write more than one time to the file, which will make writing to the file more efficient. In addition, when you buffer your output, you can use the newLine() method of the BufferedWriter object to insert a newline. The newline will be appropriate for the operating system that the program is running on. Here is an example:
    File f = new File("C:/TestData/atest.txt");
    BufferedWriter out = new BufferedWriter(new FileWriter(f) );
    String fromString = "From: Jane";
    out.write(fromString);
    //Not written to the file until enough data accumulates.
    //The data is stored in a buffer until then.
    out.newLine();
    String toString = "To: Dick";
    out.write(toString);
    out.newLine();
    String dateString = "Sent: October 27, 2006";
    out.write(dateString);
    out.newLine();
    out.close(); 
    //Causes any unwritten data to be flushed from
    //the buffer and written to the file.

  • I just got the new iPhone 4 today, and when I make calls, the screen doesn't lock, leading to accidental muting and speaker phone. Is there something wrong with my phone? Can I fix it?

    I'm just concerned that there's something wrong with my new phone.

    Do you have a case on it?
    If so, remove and see if it helps.

  • HT1595 My new apple tv 2nd gen says that there is something wrong and to check my settings, (-3902) it is all set to auto.What do i do

    My new apple tv 3rd gen says that there is something wrong and to check my settings, (-3902) it is all set to auto.What do i do?

    https://discussions.apple.com/thread/2794045?start=75&tstart=0

  • HT204266 I am trying to download Tap Tap Revenge on my new Ipad air..however..i searched for it in the App Store but there are none...help please..i really love this game! Is there something wrong with my App Store or my ipad??

    I am trying to download Tap Tap Revenge on my new Ipad air..however..i searched for it in the App Store but there are none...help please..i really love this game! Is there something wrong with my App Store or my ipad??

    It looks like the app is not currently in the App Store, I can't find it in the UK nor US stores.
    If you had previously downloaded it then do you have a copy on your computer's iTunes so that you can sync it to your iPad ?

Maybe you are looking for

  • Downloading videos from a disk.

    Okay so I tried downloading this video that I made on another MacBook on to my Macbook, so I put it in then the DVD player comes up and goes to full screen and I can't get out of it without ejecting the disk. So, how do I go about downloading the vid

  • Sapscript Print field in a row .

    Hi Friends , I have to print a field next to each other in a single row . Please let me know how to go about this . In my print program I have this: LOOP AT t_int FROM 2.         CALL FUNCTION 'WRITE_FORM'           EXPORTING             element   =

  • Understand iCloud photo streaming

    There some info that I think I already get it and I will appreciate if anyone can confirme it: 1) Pic share in "iCloud" 1.1 - It stays there pics taken in the last 30 days until a limit of 1000 pic. If after 30 days I don't reach the 1000 pic, imagin

  • Can you make changes to the regisirty om OS 10.2.8

    I need to get into the registry on my wife's iBook to get her scores from the word game Bookworm and transfer them to her new iBook. Is there such a way with Macs? Any help would be greatly appreciated. Thanks Wayne

  • "Forbidden" message when trying to access LMS 4.0

    I have installed LMS 4.0, installed the 2008 R2 patch as well.  Everything worked with SSL until I did an import from our 3.2 Solaris version.  After that, now when I access the application I get a message: "Forbidden You don't have permission to acc