Not writing to file

Hi,
I have made a program that reads a string, converts it to bytes, then writes to a file.
Well i got the first two working, but its not writing to file. I know it should work cos i have written to file on my previous tests, but when i used a FOR loop it stoped working. Do ya know why. Below is the code...
for (int a = 0;a = bytes.length - 1;a++){
of.write(bytes[a]);
System.out.print(" " + bytes[a] + " : " + bytes.length);
My friend told me to use bytes.length - 1 as it is meant to stop the OUTOFBOUNDS error.
OK,
my regards
Below is the whole program, its a bit messy cos i got lots of old code that i have blocked.
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;
public class sender implements Runnable {
int i= 0;
String mes;
int count =0;
int b = 0;
boolean yes = false;
public static void main (String[] arguments) {
Thread th = new Thread (new sender());
th.start ();
//sender();
//while (true){}
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
String mesdialog = JOptionPane.showInputDialog(null,
"Enter your message");
mes = mesdialog.toString();
try {
//FileOutputStream of = new
//FileOutputStream ("send.txt");
FileWriter of = new
FileWriter("send.txt");
//BufferedReader in = new
// BufferedReader(fr);
//while (true){}
int i = 66;
boolean eof = false;
int inChar = 0;
//String inChar;
byte[] bytes = mes.getBytes();
/* < disable / enable
do {
int n=Integer.MIN_VALUE;
try{
n = Integer.parseInt(mes);
} catch (NumberFormatException nfe){
//inChar = n;
if (inChar != -1) {
byte outChar = (byte)inChar* ;
//char outChar = (char)inChar ;
of.write(outChar);
System.out.println("" + outChar);
//of.write(mes,0,20);
} else
eof = true;
} while (!eof);//*/
for (int a = 0;a = bytes.length - 1;a++){
of.write(bytes[a]);
System.out.print(" " + bytes[a] + " : " + bytes.length);
while (!yes) {
if (bytes[b] == 32 )
yes = true;
else {
of.write(bytes);
System.out.print(" " + bytes[b]);
b++;
//System.exit(0);
//outfile.write(input);
} catch (IOException e) {
System.out.print("AAA ERROR");}

your friend was obviously wrong.
for (int a = 0;a = bytes.length - 1;a++){ // that does nothing
of.write(bytes[a]);
System.out.print(" " + bytes[a] + " : " + bytes.length);
}the above "for" loop says :
1:initialize a with 0;
2:do loop while a=bytes.length(<-that's completely wrong. it should be
a boolean expression);
3:for each loop increment "a" by one.
try this:for (int a = 0;a < bytes.length;a++){
of.write(bytes[a]);
System.out.print(" " + bytes[a] + " : " + bytes.length);

Similar Messages

  • Programme written in 6.1 is not writing to file in 7.0

    The programme written in 6.1 was designed to write data into file but i have installed labview 7.0 now and the same programme is not writing to file.

    Hi,
    Here is the detailed information.
    I am running this Labview VI for collecting data through a network analyser and controlling motion of motors through DAQ card. I have already run the cd of drivers given with Labview 7.0
    The exact subvi used for writing file is the hp8720 collect data. This thing has been installed in the Laptop with version 6.1 of Labview. What I have done is that I have taken the same programme and changed its algorithm in Labview 7.0 on a different comp and copied the file back. Then I installed labview 7.0 on the Laptop and tried running the new programme. But everything is working except the writing to file. Error handling has been put up and the message I get is Error reading/writing from/to file. Check file name.
    Kindly h
    elp out.
    Regards,
    Harshat

  • Background process not writing to file

    Hi,
    i am encountering a problem when a process is started under root in background.The application is not writing the Information to the file.
    But when i start the same application from a telnet session it works fine
    Any solution to the problem
    regds
    subbu

    your friend was obviously wrong.
    for (int a = 0;a = bytes.length - 1;a++){ // that does nothing
    of.write(bytes[a]);
    System.out.print(" " + bytes[a] + " : " + bytes.length);
    }the above "for" loop says :
    1:initialize a with 0;
    2:do loop while a=bytes.length(<-that's completely wrong. it should be
    a boolean expression);
    3:for each loop increment "a" by one.
    try this:for (int a = 0;a < bytes.length;a++){
    of.write(bytes[a]);
    System.out.print(" " + bytes[a] + " : " + bytes.length);

  • Not writing the file second time

    hi Experts
    can anybody tell me after executing this code on windows the value is not written second time to file
    the code goes like this
    import java.util.*;
    import java.io.*;
    import java.net.*;
    public class Agent
         public static void main(String args[])
              File script=null;
              File outputFile=null;
              BufferedReader check=null;
              try
                   check = new BufferedReader(new FileReader("checkThreshold.txt"));
                   String checkStr;
                   while((checkStr=check.readLine())!=null)
                        checkStr=checkStr.trim();
                        //System.out.println(checkStr);
                        StringTokenizer st=new StringTokenizer(checkStr);
                        String commandStr=st.nextToken();
                        String paramStr=st.nextToken();
                        //String wThresholdStr=st.nextToken();
                        float wThreshold=Float.parseFloat(st.nextToken());
                        //String mThresholdStr=st.nextToken();
                        float mThreshold=Float.parseFloat(st.nextToken());
                        //String cThresholdStr=st.nextToken();
                        float cThreshold=Float.parseFloat(st.nextToken());
                        script= new File(System.getProperty("java.io.tempdir"),"script.vbs");
                        outputFile= new File(System.getProperty("java.io.tempdir"),"outputFile.txt");
                        PrintWriter writer=new PrintWriter(new FileWriter(script,false));
                        //System.out.println("command is:"+commandStr+" paramis:"+paramStr+"wThresholdStr:="+wThresholdStr+" mThresholdStr:"+mThresholdStr+"cThresholdStr:"+cThresholdStr);
                             writing a script for getting value and then comparing then
                        writer.println("Dim Wsh,cmd\n"+
                             "Set Wsh = Wscript.CreateObject(\"Wscript.Shell\")\n"+
                             "Wsh.Run(\"cmd.exe\")\n"+
                             "WScript.Sleep 1000\n"+
                             "Wsh.SendKeys \"wmic /output:"+outputFile+" path "+commandStr+" get/value{ENTER}\"\n"+
                             "WScript.Sleep 1500\n"+
                             "Wsh.SendKeys \"exit{ENTER}\"\n");     
                        writer.close();
                        /***********executing the script************/
                        Process p=Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", "\""+script+"\""});
                        int exitValue=p.waitFor();
                           BufferedReader in = new BufferedReader(new FileReader(outputFile));
                        String str;
                        int cnt=0;
                        while((str=in.readLine())!=null)
                             str=str.trim();
                             String tempStr="";
                             StringBuffer buffer=new StringBuffer();
                             for(int i=0;i<str.length();i+=2)
                                  buffer.append(str.charAt(i));
                             tempStr=buffer.toString();
                             if(tempStr.startsWith(paramStr))
                                  StringTokenizer token=new StringTokenizer(tempStr,"=");
                                  token.nextToken();
                                  float value=Float.parseFloat(token.nextToken());
                                  if(value>=cThreshold)
                                       System.out.println("critical");
                                  else if(value<cThreshold && value>=mThreshold)
                                       System.out.println("major"+value);
                                  else if(value<mThreshold && value>=wThreshold)
                                       System.out.println("warning"+value);
                                  else
                                       System.out.println("normal"+value);                         
                        cnt++;
                        System.out.println(cnt);
                        script.delete();
              }catch(Exception e)
                        System.out.println(e);
    }

    I tried to redo the config objects but still the same issue is there. anyone has any idea

  • UTL_FILE.PUT_LINE   not writing to file in real time !!!

    Hi All
    I have 3 statements and I am writing some thing to a file using UTL_FILE.PUT_LINE after each statement is over. Each statement takes mentioned time to complete.
    I am opening file in append mode.
    statement1 (takes 2 mins)
    UTL_FILE.PUT_LINE
    statement2 (takes 5 mins)
    UTL_FILE.PUT_LINE
    statement3 (takes 10 mins)
    UTL_FILE.PUT_LINE
    I noticed that I am able to see contents written by UTL_FILE.PUT_LINE only after statement3 is over, not IMMEDIATELY after statement1 and statement2 are done ?
    Can anybody tell me if this is correct behavior or am I missing something here ?
    Thanks a lot in advance.

    AnkitV wrote:
    Hi All
    I have 3 statements and I am writing some thing to a file using UTL_FILE.PUT_LINE after each statement is over. Each statement takes mentioned time to complete.
    I am opening file in append mode.
    statement1 (takes 2 mins)
    UTL_FILE.PUT_LINE
    statement2 (takes 5 mins)
    UTL_FILE.PUT_LINE
    statement3 (takes 10 mins)
    UTL_FILE.PUT_LINE
    I noticed that I am able to see contents written by UTL_FILE.PUT_LINE only after statement3 is over, not IMMEDIATELY after statement1 and statement2 are done ?
    Can anybody tell me if this is correct behavior or am I missing something here ?Calling procedure must terminate before data is actually written to the file.
    It is expected & correct behavior.

  • File Receiver Adapter is not writing the file?

    Hi All,
    I am having a file to file scenario using NFS as both the source and destination are on server.
    File is getting picked up from server but not reaching the destination.
    In RWB for Receiver channel it only shows <b>Channel active and started correctly.</b>
    In SXMB_MONI  it shows the message scheduled for some later time.
    On reaching that time it tries again and reschedules :(.
    Please guide.
    Regards,
    Sumit

    Sumit,
    Now do one thing, just for check the directory for read/write permission by putting the test file manually on your target directory.
    The porcedure to put a file on server is as shown below:
    1. Save your file in your local machine.
    2. In <b>XI server</b>, enter the tranaction code "<b>SXDA_TOOLS</b>".
    3. In the input screen, enter:
    i) Object Type "DXPROJECT".
    ii) Program Type "BAPI".
    iii) Program "CREATE".
    4. Press Copy (Ctrl+F5) button.
    5. Now, you will get another screen in which you will see 3 blocks called as "Source", "Target" and "Copy with/without conversion".
    6. In Source block, choose the radio button "Presentation Server" and then take F4 help to select your source file. (file which you have saved on your local machine)
    7. In source block select the radio button "Application Server", check the box "Remote server" and take F4 help to select your application server.
    8. In the same block under "File Type" select "P physical file name" and under "File Name" write the path/directory name which you have mentioned in your communication channel along with the file name.
    Example: suppose file name in your Comm Chanel is "<b>demo.xml</b>" and directory path is <b>"/abc/testfiles/XML/</b>", then in step 8 write <b>"/abc/testfiles/XML/demo.xml</b>".
    Note: need not to do any thing in 3rd block.
    After doing all the above, let me know the results.
    Regards,
    Sarvesh
    ****Reward points, if it helpd you.

  • File adapter not writing the file correctly

    Hi,
    I am facing an issue where the file created on the destination is not with the correct data. eventhough the payload that was sent out from XI to the adapter is correct.
    Issue was with a mltiple element which was written once eventhough the payload shows multiple existance.
    we had changed the occurance of that element from 1 to unbounded.
    If anyone has any idea do let me know
    Regards
    Nikhil

    I tried to redo the config objects but still the same issue is there. anyone has any idea

  • LR not writing XMP files in an exisitng catalog

    Hi Folks
    My problem is regarding XMP files. I read on a couple of forums that turning on the xmp files is a good idea...... (Automatically write changes into xmp) OK so I thought lets try it....
    If I turn this option on in my existing catalog it does not work, no xmp files are written.
    I have tried creating a new catalog and importing some RAW files and it seems to work just fine..... xmp files are created as expected.
    So is this option only for new catalogs or can I use it on existing catalogs....
    Many thanks in advance
    Regards
    batandball
    My config is the following
    LR 5.7
    Win 8.1

    The files that were previously imported prior to the activating the "Auto write to xmp" will have to be updated using the menu bar> Metadata> and selecting the option to write to xmp. (or Ctrl-S)
    Be aware that the develop module edits saved as xmp is only useful to an equivalent version of Adobe Camera Raw plugin in Photoshop.

  • My computar is not writing AIFF files correctly

    It seems whenever it write an AIFF file (or a WAV, or an MP3 for that matter) the bass frequencys are boosted by about 4db. I used to think this was just a problem with Logic mixing (which also causes me a lot of frustration) but it now seems to be happening across the board.
    For example, I used wire-tap to lift a song of the internet, but upon listening to the said file it turned out the bass has been increased by a bizzare amount for no reason.
    The final proof came when I decided to rip a song off a CD and put it in Logic. Upon re-bouncing the file I discovered the bass frequencys had been pumped up in a most irritating manner. This happened again when I used wire-tap to rip the tracks off the CD as they were playing in the computer. This problem does not occur when I drag and drop the files off the CD and onto the desktop.
    I think this all points to something being wrong with my computer software.
    This problem is ruining all my very loud, sublimely beautiful mixes at the bounce stage and it's getting so bad now I'm thinking of backing up my files, formatting the hard drive, and reinstalling OS X.
    DISCLAIMERS:
    1. EQ on iTunes is SWITCHED OFF.
    2. My monitor equipment ALSO HAS A FLAT EQ.
    2a. When I play a track on my listening equipment from a CD IT SOUNDS FINE. Only after processing the VERY SAME track in LOGIC and BOUNCING IT does this problem COME UP.
    2b. This happens EVEN IF THERE IS NO EQ on either the MASTER OUT or the AUDIO TRACKS.
    3. I HAVE TRIED ALL FILE FORMATS, ALL KINDS OF DITHERING AND NOTHING CHANGES THE OUTCOME.
    4. This never used to happen.
    5. I am using the latest version of Logic Pro (7.1.1) compatible with Mac OS 10.3.9.
    If you fix my problem I will reward you with £10 to be paid into your pay-pal account (if you have one). I hope this underlines how sick I am of this problem and how desperate I am to get it fixed.

    Hi,
    This sounds so frustrating. If any processing of sound, e.g. through Logic, through Wiretap, or you might try Garageband (which I assume you have tucked away somewhere), produces the problem, then its hard to blame the software of the individual program. This leaves OSX and/or Coreaudio, or a hardware problem. Sorry if you've already reached this stage. This would mean a reinstall of OSX (or an upgrade, if you're thinking of it), or addressing the hardware issue. I know I had some very bizarre things (and repetitive) happen to me with faulty memory, or memory that just wasn't seated properly in its slot. You could start out by running the hardware test and go from there.
    Good Luck,
    Ray

  • FTP Adapter not writing the file in FTP directory

    We have desiged BPEL Process which will get data from Oracle and write in txt file in FTP directory.
    For last few days, we are getting following error when we invoke the BPEL Process:
    file:/u102/product/10.1.3.1/OracleAS_1/bpel/domains/default/tmp/.bpel_XXADS_INT033_DEL_EBS_OUT_1.0_0be42a99260084d9bd5104929a8ac1b2.tmp/DELFTPservice.
    wsdl [ Put_ptt::Put(opaque) ] - WSIF JCA Execute of operation 'Put' failed due
    to: Error saving control file.
    Error saving control file: "/u102/product/10.1.3.1/OracleAS_1/j2ee/home/fileftp/controlFiles/ZmbNdvlpVkaee+
    OddQzH2Q==/outbound/controlFile_ob.properties"
    ; nested exception is:
    ORABPEL-11080
    Error saving control file.
    Error saving control file: "/u102/product/10.1.3.1/OracleAS_1/j2ee/home/fileftp/controlFiles/ZmbNdvlpVkaee+
    OddQzH2Q==/outbound/controlFile_ob.properties"
    Please make sure that a valid control file exists.
    Can anyone help me to resolve this?
    Thanks,
    Hariharan Ramakrishnan

    I tried to redo the config objects but still the same issue is there. anyone has any idea

  • Metadata not writing to file, metadata status "..."

    Until recently, I am sure that saving metadata to file worked fine.  Now, when I do it for a selection, it appears to write (with disk activity and dialogue of files being updated), but then afterwards I still have <mixed> status on the set.  Some within are updated, others show status <...>.
    Catalogue says there is no corruption - so what's going on?  How do I fix it?  And should I worry about teh state of my images?
    Thanks for any help

    Now see that when I save for some that show "Changed", it writes, then returns to
    say either "..." or back to "Changed".  It seem to think that the catalogue has some changes each time.

  • Problem with Write To Measurement File Express VI not writing to file if file was deleted after the first call (7.1)

    I'm using the Express Write to LabVIEW Measurement File in LV7.1.
    I have it set to "Save to one file"  and have tried both "Overwrite file" and "Using next available file name" for the "If a file already exists" conditions.
    The path/filename is passed into the function.
    It works fine the first time around.  If the file is deleted before the function is called again, an error occurs since LV is unable to find the file.
    I have had to stop and re-run my program in order to write to use the function again.
    Since I am able to delete the file I assume it was closed but it seems like LV expects it to be there, even though the function was supposed to create/open/close the file...  Is there any way to reset this without stopping/restarting the program?
    Since my application creates several files (only one using the Express VI) I am checking for the filenames and requiring that they be deleted (or a new filename be used) before acquiring data.  Everything has worked great, except for the Express VI.
    Thank you,
    David

    Ok, I've edited the VI you posted to reproduce my error (this time with 8.0). 
    I added a "master stop" and "start log" button.  To demonstrate my problem:
    1.  Run the VI
    2.  Click "START LOGGING" - c:\test.txt is created
    3.  Click "STOP" - c:\test.txt is closed
    4.  Delete the file c:\test.txt with Windows shell or explorer
    5.  Click "START LGGING" - a new c:\test.txt file should be created but instead an error is raised in the Write LabVIEW Measurement File function.
    Any ideas?
    Thanks,
    Dave
    Attachments:
    Write LV Meas File 2.vi ‏96 KB

  • CVI 2010 distributi​on not writing / updating files

    Hi,
    I have recently an installation/distribution of some software created in CVI 2010 to a client whoes PC's hard-drive had failed. They re-installed the software ok and it ran a test but when they came to save the data or any of the machine settings non of the files were updated.
    They are using Windows 7 and I asked them to run the executable again as an administrator but still the same problem.
    I then sent them a copy of just the application (which was the same as the one they had installed) and they manually copied this onto the PC  overwritting the version that had been installed and it all ran ok.
    Is there something Windows 7 is doing with the installation and security/permissions? Is there anything I can set when creating the distribution that can overcome this?
    Thanks

    Hi Dave,
    It sounds like there may be access rights issues with the files you are creating/saving within your program. Which windows directory do you write your files to from within the exe? For the example the root (C) directory by default on Windows is typically restricted in access, even for the Administrator until it's disabled.
    Kind Regards,
    Paul
    http://www.paulharris.engineering

  • Writing to file in JUnit test case? Not working?

    I have a singleton class called InstantLogger that internally uses a PrintWriter to write to file. It is very basic, has startLogger(String filename), log(String msg), and stopLogger(). startLogger just creates file, log write to file, and stopLogger closes file.
    When I use this class outside of the JUnit test suite it works fine.
    As soon as I use it in a JUnit test it does not write to file. It creates the file (this happens in the TestSuite), but will not write anything to it (when log is called from TestCase). I put a System.out in the log function and I see that, but still nothing writing to file. And I will say it again, it does work in non TestCase scenarios so I know it works.
    Is there something that could be preventing me from writing to file in JUnit TestCase? Could this be a Singleton Issue?
    Thanks,

    avalanche333 wrote:
    I have a singleton class called InstantLogger Ouch.
    that internally uses a PrintWriter to write to file. It is very basic, has startLogger(String filename), log(String msg), and stopLogger(). startLogger just creates file, log write to file, and stopLogger closes file.
    When I use this class outside of the JUnit test suite it works fine.Oh, brother.
    >
    As soon as I use it in a JUnit test it does not write to file. It creates the file (this happens in the TestSuite), but will not write anything to it (when log is called from TestCase). I put a System.out in the log function and I see that, but still nothing writing to file. And I will say it again, it does work in non TestCase scenarios so I know it works.
    Is there something that could be preventing me from writing to file in JUnit TestCase? Could this be a Singleton Issue?Um, no.
    Your code is wrong. You're assuming something that isn't correct. You're also making the assumption that just because it "works" in another context that it's right in all contexts. The two aren't the same, be it configuration or something else.
    Singleton? That GoF pattern has been voted off the island. Didn't you hear?
    http://code.google.com/p/google-singleton-detector/
    %

  • Please can anyone help me..I can not get itunes to install,i get a error message writing to file c and says i need to verify access to directory please help me

    I need help in trying to install I Tunes,,,after multiple attempts I have now pulled all my hair out,and I am without I Tunes,,,I have tried everything ,and all the ideas that I have found in trying to seach the reason for my problem.it will download quick time,,,it gets about half way through I Tunes and I get a error message that says...........Error writing to File C /program files x86  itunes .tunes exc.verify you have access to that directory......I need the wisdom of any and all that are smarter than I about this issue.........I would appreciate any and all help ..thank you....

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    Setting up and troubleshooting Mail
    http://www.apple.com/support/ipad/assistant/mail/
    Server does not allow relaying email error, fix
    http://appletoolbox.com/2012/01/server-does-not-allow-relaying-email-error-fix/
    Why Does My iPad Say "Cannot Connect to Server"?
    http://www.ehow.co.uk/info_8693415_ipad-say-cannot-connect-server.html
    iOS: 'Mailbox Locked', account is in use on another device, or prompt to re-enter POP3 password
    http://support.apple.com/kb/ts2621
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Configuration problems with IMAP e-mail on iOS with a non-standard SSL port.
    http://colinrobbins.me/2013/02/09/configuration-problems-with-imap-e-mail-on-ios -with-a-non-standard-ssl-port/
    Try this first - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.)
    Or this - Delete the account in Mail and then set it up again. Settings->Mail, Contacts, Calendars -> Accounts   Tap on the Account, then on the red button that says Remove Account.
     Cheers, Tom

Maybe you are looking for