Data written in file doesnt remain the sme!!

Hey guys
I am writing a small app for myself to store imp data like my IDs, passwords etc.
I want this application to
-accept string
-get ASCII value of each character
-make cipher by changing ASCII values
-store new characters in a file.
The code is working fine however there is a problem when I store cipher in file.
Suppose I am converting --
Text - abc
using password - ab
ASCII values of characters stored in file should be-
388 392 390 197 199
the first 3 characters in file show up as "?"
when this app reads file, it reads characters in file as "?" and take ASCII value 63.
Is there any way I can make those chars retain their ASCII values?

Navy_Coder wrote:
the read() method does not guarantee to read all the bytes requested. Much better to use DataInputStream.readFully(). I've always interpreted the documentation where it says "try to read as many as len bytes..." to mean, "It'll read that many bytes if they're available, but if for some reason they're not, it'll return the number of bytes you've actually read." So what constitutes "if they're available" ? I have seen too many posts where people have intermittent read problems when expecting the read to return all the bytes requested. Nothing in the specification of the read(byte[] ) method says it has to read more than just one byte.
In this particular instance, I find it hard to imagine a scenario where you've written a small number of bytes to a file (limited to how many the user wants to enter by hand in a single line on the terminal in our example) that are not available for reading from an InputStream.Possibly but why not make it bullet proof and used DatainputStream. Your code may be taken by the OP and some other inexperienced Java developers as indicating how to read the content of a file into memory. The approach is flawed and it is so easy to make bullet proof that it does not make sense not to do so.
>
If you're dealing with streams where the availability of these bytes will be questionable - and you want to guarantee that you do not return until all of the bytes you've requested have been read - then DataInputStream.readFully is reasonable. Another option is to loop, using the InputStream.read() method, until all bytes have been read.This looping is what readFully() does behind the scenes so why not make use of it rather then rolling your own.
>>
:-) Maybe you should have taken 11 minutes!Maybe.You happen to have hit upon two of my pet gripes. 99% of the time it is wrong to use String.getBytes() and new String(bytes) without explicitly specifying the encoding. 100% of the time it is wrong to assume that the number of bytes read by InputStream#read(byte[] ) will be the number requested.

Similar Messages

  • How to export the text edit data to excel file without splitting the data in excel file?

    how to export the text edit data to excel file without splitting the data in excel file?
    I have a requirement in SAP HR where in the appraiser can add comments in the area given and can export that to excel file. Currently the file is getting exported but the comments getting split into deifferent rows.
    I want the entire comment to be fit in one row.
    Please help.
    Thank you

    Hi,
    if your text edit value is stored in 'lv_string' variable.
    then before exporting the value to excel you have to remove CL_ABAP_CHAR_UTILITIES=>NEWLINE
    that is '#' from the variable lv_string.
    for that use code some thing like this.
    REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>NEWLINE in lv_string WITH space.
    I think this will do the trick.

  • In Firefox 4 how can I cause the date on downloaded files to be the current date? (Some are and some are not. In FF3 the dates were ALWAYS the current ones.)

    In Firefox 4 how can I cause the date on downloaded files to be the current date? (Some are and some are not. In FF3 the dates were ALWAYS the current ones.)
    == This happened ==
    Every time Firefox opened
    == I upgraded to Firefox 4 (beta)

    Firefox 3.6.* and earlier set the downloaded file's modification time to the current time. In Firefox 4.0 the behavior has been changed, if a server returns a timestamp telling when the file was last modified (Last-Modified header), it is used instead.
    You can revert to the previous behaviour by using the [https://addons.mozilla.org/en-US/firefox/addon/93121/ Download Timestamp] add-on.

  • Save data in a file and email the file

    Dear all,
    I have 2 vi files:
    1. one vi file can store data into a file when it runs and stopped
    2. another vi can send a file out through email when it is run.
    Is it possible for me to run the first vi and stop after one hour (to store data into A file), then run the second vi file and stop (to send A file through email), and then run the first vi again immediately after running the second vi? This is because I need to send out my data saved hourly through email and get my 1st vi to continue running through out the day.
    Due to the file path for my first vi and the second vi are the same, I keep getting error as below when either 1 vi is not stopped.
    Error 5 occurred at Open/Create/Replace File in Write Spreadsheet String.vi->Write To Spreadsheet File (DBL).vi
    Please advice. Thanks.
    Kim

    Dear Ravens,
    I tried to kill (remove) the event structure from my earlier code, but as I run it, I get the same error again- error 5.
    I also tried to put time out value 200 at the timenode at the upper left of the event structure but the email part just never executed.
    I searched thru the forum and found a several examples on state machine as attached. I tried the first attachment for my program but obviously I used the wrong one as you adviced. As for the other state machine examples that I downloaded, I couldn't figure out how to apply them for my case correctly. Can you advcice how can I implement state machine to get the results tat I need?... Pls gv me some clearer hints? 
    Attachments:
    QueuedStateMachineWithEvents.vi ‏49 KB
    StandardStateMachine_2MOD.vi ‏19 KB
    JKI State machine.vi ‏75 KB

  • Loading data into csv file based on the count of data in table in ODI

    Hi,
    I have a requirement like i have data in table and need to be loaded in csv file.
    If the count of the data in the table exceeds the csv data limit then i need to call the same procedure again to
    generate one more csv file and load the remaining data into it.my data in the table may vary all the time.
    I am new to this ODI.Can anyone tell any ways to do it in ODI or tell me any logic to do this?
    Thanks in advance..
    Edited by: 883410 on May 22, 2012 12:01 AM

    What limit on the csv file are you talking about. There isn't a limit (unless you are on Unix where the filesize is limit is 2GB). Are you talking about opening it in earlier versions of Excel where the display limit is 60,000 rows as this is irrelevant for your operation?

  • How can I Read lines of data from a file starting at the end of the file??

    Can anyone help me with how to read lines of data starting from the end of a file instead of the beginning?? I do not want to load the entire file into memory as the files are very rather large. Instead I want to start at the end of the file and read lines backward , until I find the particular data item i am searching for, then stop.
    Can this be done in Java ? I know it can be done in Perl.
    Thanks.

    Thanks for your suggestion about the RandomAccessFile, I did actually thought about that approach , but wasn't sure it would work.
    I do not want to read the file in a sequential forward manner because the files contain large number of lines of data that have already been processed and therefore there is no need to reprocess these lines of data.
    The Unprocessed lines are always at the the end of the file and these are the data lines I am interesting in getting at without having to read the entire file. Therefore, i figure that if I can read the data from the end of the file then this would be much more efficient.

  • AI plug cant read CAD 04 file, doesnt understand the file?

    Illustrator won't open saved down CAD files says, 'cant read file because it doesn't understand the file?

    CS6, bringing in info from CAD 2014, on a PC, I got it to work, apparently, when I xref images from county assessor page, AI doesnt' recognized the file type imbedded with the CAD file.  I believe the image attaches as a png.  Once I detached the image from the CAD file, I was able to open it sucessfully.  Thanks for the response.

  • 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());

  • Deleteing files doesnt increase the free space on my harddisc

    My hard disc has only 766 MB free space. When I´m deleteing files I don´t get more free space.
    I have deleted over 1 GB today by putting files into the trash can and then empyting it, but it is still only the 766 MBs of free space.
    Help?

    I dont understand the word "sparse". What is this file? Can i delete it?
    This file contains your encrypted home folder. As long as you have FileVault turned on, don't delete it.
    I have FileVault enabled but when I try to disable it it says that there is not enough free disk space.
    Try the suggestions on this page.
    (16342)

  • Why would only the first line of my data set txt file work?

    Hi -
    I had a lot of success using variables and external data sets until today.
    I have an external text file that I have imported as a data set (Image/Variables/Data Sets/Import...).  All of the variables have been defined and confirmed (at least PSD hasn't told me it can't find something which is the typical error msg.)
    This external text file, with the extension ".txt" has 12 lines on it, each line is 7 comma separated values, and each line is ending in a carriage return.
    YESTERDAY when I used File/Export/Export Data Set as Files... the procedure went beautifully for the 8 times I used it.  TODAY I only get the first of the 12 lines completed and then the export stops.  There are no error messages or other signs that Photoshop has choked on something so I guess something is wrong with my text file... BUT WHAT??
    Any insight on any step in this would be helpful.  You all know that if I'm using this feature it's because I have TONS of repetition ahead of me if it doesn't work.
    TIA your expertise,
    JL

    Fixed it!
    When Exporting as Data sets as files... the step I missed was to select "All Data Sets" from the Data Set drop down.
    Thanks all.
    JL

  • Need solu to Append the data frm different files..Element 'Rec' not expecte

    i need solution to append the data coming from different files.
    sample file is of format
    Header Records
    Data Records
    i need to append the data coming from files to single file which consist of single header and data records from all the four files.
    Using assign activity to append the Data Record. but not able to force the data to write in the target location
    Facing following error..
    Record in the below error is data records. i can view all the appended data put variable.but facing following error Element 'Record' not expected.
    <Record>
    <RecType>1</RecType>
    <SSAppsID>ICD </SSAppsID>
    <TSAppsID>NPS </TSAppsID>
    <FileType>CUSTOMER</FileType>
    <SeqNo>0030</SeqNo>
    <CusNum>50902 </CusNum>
    <CSAppID>ICONS </CSAppID>
    <CusName>YTL Communications Sdn Bhd </CusName>
    <OldIDCardNum/>
    <NewIdentyCardNum/>
    <PassPortNum/>
    <BusinessRegNum/>
    <Police_armyPerNum/>
    <SEGCode>W20</SEGCode>
    <SecCode/>
    <NewSegCode/>
    <IcareMAsterAccNum/>
    </Record>
    </Record>
    </Root-Element>
    </part>
    </PutFilesToTarget_Put_InputVariable>
    </input>
    <fault>
    <bpelFault>
    <faultType>0</faultType>
    <bindingFault>
    <part name="summary">
    <summary>Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'Put_InboxNew' failed due to: Translation Error. Translation Error. Error while translating message to native format. Please make sure that the payload for the outbound interaction conforms to the schema. ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution. </summary>
    </part>
    <part name="detail">
    <detail>Element 'Record' not expected.</detail>
    </part>
    <part name="code">
    <code>null</code>
    </part>
    </bindingFault>
    </bpelFault>
    </fault>
    <faultType>
    <message>0</message>
    </faultType>
    </messages>

    ya i am reading the data and writing the data with the same format..
    but i need to append data from different files..eliminating the header from second file..
    i am invoking the write adapter out of the while loop..
    this seems some problem while writing..its looking for data records still..

  • Java.io.NotSerializableException when overwrite the JTable data into .txt file

    hi everyone
    this is my first time to get help from sun forums
    i had java.io.NotSerializableException: java.lang.reflect.Constructor error when overwrite the JTable data into .txt file.
    At the beginning, the code will be generate successfully and the jtable will be showing out with the data that been save in the studio1.txt previously,
    but after i edit the data at the JTable, and when i trying to click the save button, the error had been showing out and i cannot succeed to save the JTable with the latest data.
    After this error, the code can't be run again and i had to copy the studio1.txt again to let the code run 1 more time.
    I hope i can get any solution at here and this will be very useful for me.
    the following is my code...some of it i create it with the GUI netbean
    but i dunno how to attach my .txt file with this forum
    did anyone need the .txt file?
    this is the code that suspect maybe some error here
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String filename = "studio1.txt";
              try {
                  FileOutputStream fos = new FileOutputStream(new File(filename));
                  ObjectOutputStream oos = new ObjectOutputStream(fos);
                   oos.writeObject(jTable2);
                   oos.close();
              catch(IOException e) {
                   System.out.println("Problem creating table file: " + e);
                   return;
              System.out.println("JTable correctly saved to file " + filename);
    }the full code will be at the next msg

    this is the part 1 of the code
    this is the full code...i had /*....*/ some of it to make it easier for reading
    package gui;
    import javax.swing.*;
    import java.io.*;
    public class timetables extends javax.swing.JFrame {
        public timetables() {
            initComponents();
        @SuppressWarnings("unchecked")
        private void initComponents() {
            jDialog1 = new javax.swing.JDialog();
            buttonGroup1 = new javax.swing.ButtonGroup();
            buttonGroup2 = new javax.swing.ButtonGroup();
            buttonGroup3 = new javax.swing.ButtonGroup();
            buttonGroup4 = new javax.swing.ButtonGroup();
            jTextField1 = new javax.swing.JTextField();
            jLayeredPane1 = new javax.swing.JLayeredPane();
            jLabel6 = new javax.swing.JLabel();
            jTabbedPane1 = new javax.swing.JTabbedPane();
            jScrollPane3 = new javax.swing.JScrollPane();
            jTable2 = new javax.swing.JTable();
            jScrollPane4 = new javax.swing.JScrollPane();
            jTable3 = new javax.swing.JTable();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
    /*       org.jdesktop.layout.GroupLayout jDialog1Layout = new org.jdesktop.layout.GroupLayout(jDialog1.getContentPane());
            jDialog1.getContentPane().setLayout(jDialog1Layout);
            jDialog1Layout.setHorizontalGroup(
                jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 400, Short.MAX_VALUE)
            jDialog1Layout.setVerticalGroup(
                jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 300, Short.MAX_VALUE)
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jLayeredPane1.add(jLabel6, javax.swing.JLayeredPane.DEFAULT_LAYER);
            String filename1 = "studio1.txt";
            try {
                   ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename1));
                   jTable2 = (JTable) ois.readObject();
                   System.out.println("reading for " + filename1);
              catch(Exception e) {
                   System.out.println("Problem reading back table from file: " + filename1);
                   return;
            try {
                   ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename1));
                   jTable3 = (JTable) ois.readObject();
                   System.out.println("reading for " + filename1);
              catch(Exception e) {
                   System.out.println("Problem reading back table from file: " + filename1);
                   return;
            jTable2.setRowHeight(20);
            jTable3.setRowHeight(20);
            jScrollPane3.setViewportView(jTable2);
            jScrollPane4.setViewportView(jTable3);
            jTable2.getColumnModel().getColumn(4).setResizable(false);
            jTable3.getColumnModel().getColumn(4).setResizable(false);
            jTabbedPane1.addTab("STUDIO 1", jScrollPane3);
            jTabbedPane1.addTab("STUDIO 2", jScrollPane4);
            jTextField1.setText("again n again");
            jLabel6.setText("jLabel5");
            jLabel6.setBounds(0, 0, -1, -1);
            jButton2.setText("jButton2");
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
          

  • Change the Data and Log file locations in livecache

    Hi
    We have installed livecache in unix systems in the /sapdb mount directory where the installer have created sapdata and sapdblog directories. But the unix team has already created two mount direcotries as follows:
    /sapdb/LC1/lvcdata and /sapdb/LC1/lvclog mount points.
    While installing livecache we had selected this locations for creating the DATA and LOG volumes. Now they are asking to move the DATA and LOG volumes created in sapdata and saplog directories to these mount points. How to move the data and log file and make the database consistent. Is there any procedure to move the files to the mount point directories and change the pointers of livecahce to these locations.
    regards
    bala

    Hi Lars
    Thanks for the link. I will try it and let u know.
    But this is livecache (even it uses MaxDB ) database which was created by
    sapinst and morover is there any thing to be adjusted in SCM and as well as
    any modification ot be done in db level.
    regards
    bala

  • IS BT CLOUD ALTERING THE "MODIFIED DATE" ON MY FIL...

    Hi
    I have BT Cloud 2GB Free running as both the downloaded "auto sync" software and also using the Chrome Browser Interface. I am on Windows XP.
    I only use Cloud to backup word / excel documents and family photos - basic things I just dont want to risk losing.
    I recently noticed something odd, when I sorted my BT Cloud View by "Date Modified" about twenty very 'old' files suddenly appeared at the top of the view - files I hadnt used in about 5 or 6 years.
    I definitely had not accessed these files yet when I went to look at them in "My Computer" and clicked on "Properties" I could see that the "Modified Date" had changed. In fact it seems that about a dozen or so files had been "modified" over night while my PC was left on in the next room. No other dates had changed on the files - it did not look like they had been "Re-Saved" I dont think since the original author had not changed.
    I started to monitor this and noticed about half a dozen files having their "modified dates" changed every day for the last three or four days. Its only Documents (Word Powerpoint Excel Text etc) that are being modified.
    And heres the thing - I ran a search on my computer of files modified in the last week and the only ones where I could not explain the change were files that are being backed up by "BT CLOUD" so its slightly possible there is a link. Of course this could be coincidence but I thought this might be a good initial avenue to explore since without BT Cloud's interface view of my files I would never have even noticed the problem in the first place.
    I'm pretty sure its not a Virus - I run my own Scanner every few days, its always up to date and I have Real Time Scanning enabled. I also ran a couple of online scans last night (Norton etc) and they found nothing.
    Its a recent development because I use Cloud every week and would have noticed before if things were changing.
    So a couple of questions really:
    Firstly has anyone else experienced this problem - I read somewhere that Some Virus Scanners can alter the Modified Date on your files unintentionally but the MS hotfix says this only happens in Vista/Win 7 I think and I am on XP. Could it be that when BT Cloud Scans the file it affects its modified date on your PC ?
    Secondly Could anyone else access my files in BT Cloud and modify them, and if so would that change to the 'online file' be represented back on my own PC when I "Synced" my backup
    Many thanks in advance for any help anyone can offer.

    I assume your raws are in DNG format? If xmp is in sidecar, it won't change raw file date.
    Anyway, saving xmp does not change any dates in Lightroom, so you should still be able to sort by edit time or capture time...
    But if you want control, you have to save manually instead of automatically.
    Two things that might help:
    1. Filter based on metadata status.
    2. robcole.com - DNGPreviewUpdater
    Rob

  • How can I read and display data with OR without recording at the same time?

    Hi all,
      This forum has been of much help to me, but I have a rather specific question I can't seem to find an answer to.  I am new to LabView, educating myself with tutorials, trial and error, and this forum. 
      Attached is what I have so far.  I would like to read data (three voltages) and write it to an excel file.  As written below, it will do nothing until I click the "Record" button, when it then takes data, displays it on the gauges and waveform chart, and writes it to a file.  What I would like it to do is display the data at all times, and record when I click the record button (while still displaying data being read).  I have tried to do this by moving the DAQ Assistant VI, gauges, and waveform graph outside of the loops, but when I do this, it will read until I press record, and then it simply records whatever value it's stuck on.  Sorry for the long post, thanks for any help. 
      --Nathan
    Attachments:
    Record and Write to File 2.vi ‏332 KB

    Sorry, I don't have any DAQ installed, so I won't comment on the DAQ parts.
    First of all, Your VI will do nothing until you (1) first set the record button to ON  and (2) press the start button in the tool bar. It almost seems that you are using the "continuous run" button. (Don't! That's not its purpose. Basically, it automatically restarts the program whenever it finishes). A toplevel VI should never stop during normal operation, so place a big while loop around all code and create a wait state that does nothing until you tell it to acquire.
    You don't need the inner while loop, simply place your code inside the big while loop (and accumulate your array data in an initialized shift register if really needed. Currently you do at the inner loop boundary for some reason). You have a big problem that the array can grow without bounds unless you clear the accumulated data once in a while or place it in a FIFO buffer of limited size. If you let ot grow forever like you do now, the program might run out of resources at one point in the future.
    Since you are appending to your file, maybe yo don't need any shift register, just use the data points of the current iteration. Place your save operations in a case structure and keep appending the new data to your file only if the case is true.
    It is also very inefficient to use highlevel file IO here,because each instance opens and closes the file. I recommend to open the file once outside the loop, then use low level IO to append, and close the file once the big loop is done.
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for

  • HP OfficeJet Pro 8500 half recognized

    I just got a (wired) hp 8500, and plugged it into the USB port of an Airport Extreme. It works with a MacBook Pro connected wirelessly to the base station, but not with a G4 connected wired-ly to it. In fact, the OS X 10.4 G4 freezes whenever it's as

  • How do I / Can I access "prior" pages in a PDF Doc in iBooks?

    I am producing a pdf document that is a decisiopn tree that is to be used on an iPad or iPhone in, of course iBooks for species identifications.  I create the book in Pages (for the vector graphics & text) and am placing links using Acrobat.  I would

  • Import of RAW+JPEG pairs?

    Just when I thought I had it all together...I seem to have forgotten where I put it. I need some expert assistance. Aperture manages my Library which is kept on an external HD. I shoot RAW+JPEG on my D200--two image files for every shot. To anticipat

  • How do you change the Spotlight Search from Google to Yahoo???

    Does anyone know how to change the Spotlight Search setting in Safari 4 (Non Beta) from Google to Yahoo? I assume there is a way to do this though Terminal but all I can find are commands for the the Beta and not he final version.

  • No add-on sounds, but sounds from websites [video, etc] are just fine.

    But the download completed sound from download status bar or down them all are not working. I've already looked at my 'mixer' under the volume control on Win7, I also went from Firefox 11.0 to Aurora 12.0a2 with still no sound. All add-ons are up to