FileInputStream read problem

Hi!
I have a problem with reading a byte[] buffer from a file using the FileInputStream:
----- code example -----
File = new FileInputStream(filename);
data = new byte[File.available()];
File.read(data);
String test = new String(data);
----- end example -----
So, when I print the bytes of the array "data", some chars are strange (negative numbers).
When I convert the byte array into a string, some of the ASCII codes of the string's chars are wrong (like 65533).
What can I do?

It totally depends on what kind of data you're trying to read in choosing between a reader and an input stream. If you're reading binary data (like an image), use the input stream and read bytes. If you're trying to read character data, use a reader:BufferedReader reader = new BufferedReader (new FileReader ("test.txt"));
String line;
while ((line = reader.readLine ()) != null) {
    // process line
}Kind regards,
  Levi

Similar Messages

  • FileInputStream.read()  and non-blocking file i/o

    According to the API, FileInputStream.read() is :
    public native int read() throws IOException
    Reads a byte of data from this input stream. This method blocks if no input is yet available.
    Returns:
    the next byte of data, or -1 if the end of the file is reached.In what instances does the read() blocks? Is there a danger that the call to read() would block forever?

    thanks martian!
    is the ff code right enough to prevent i/o blocking?
      FileInputStream fis = new FileInputStream(src);
      FileOutputStream fos = new FileOutputStream(sPersistorFolder+src.getName());
      if(fis.available() > 0) {
        int c = -1;
        while((c=fis.read()) != -1) {
          fos.write(c);
      fis.close();
      fos.close();

  • FileInputStream.read returning negative values

    I'm trying to read binary data from a file and convert it to decimal. If I use a hex editor, through one section, I'll see the values as they actually are. Using read() on a FileInputStream object seems to randomly create negative values which are sometimes correct if I use Math.abs(), and sometimes theyre not. I don't have a clue what's going on and it's getting frustrating, as FileInputStream.read() supposedly returns an integer between 0 ane 255, which is what I'm expecting.
    Thanks for the help!

    Are you doing something like this...
    byte value = in.read();
    int useIt = value;If the value is being stored in a byte and then cast to an int, the sign bit will be extended and it will become negative. This is because a java byte is actualy +/- 127.
    To solve it, you do this..
    int useIt = value & 0xff;or never store it as a byte in the first place.
    This is what you have to do when reading bytes out of byte arrays...
    int useIt = byteArray[index] & 0xff;

  • Image reading problem in servlet

    Image reading problem in servlet
    I am reading an image in servlet and writing it to ServletOutputStream
    The following code works fine unless I change the size of the byte array (for increasing download speed) from 8 to something like 128 or any other higher value
    If I change the value of byte array size the image does not get downloaded properly, I mean the quality of the image changes, it does not looks like the original imageURL url = new URL("http://www.mysite.com/images/img1.jpg");
    URLConnection con = url.openConnection();
    con.setUseCaches(false);
    BufferedInputStream in = new BufferedInputStream(con.getInputStream());
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
    byte b[] = new byte[8];
    while(in.read(b) != -1)
         out.write(b);
         out.flush();               
    out.close();
    in.close();what do I change
    byte array size
    or use the constructor of BufferedInputStream with 2 parameter
    or use the constructor of BufferedOutputStream with 2 parameter
    or use flush outside while loop or what else

    Change your while loop to:
    int count;
    while((count = in.read(b)) != -1)
         out.write(b, 0, count);
         out.flush();               
    }The penultimate time read is called, it may not fill the entire byte array. You only want to write out however much was read into the array.
    For better performance, you should move the flush() outside of the loop too. BufferedOutputStream will flush automatically when its internal buffer is full.

  • Telnet read problem -- Telnet read back

    I am trying to use telnet to send TL1 command to my UUT and expect to read back measurement data.  I was able to read proper data once in a while but most of the time I read back the TL1 command that I sent.  I tried different read mode and timeout period but nothing seem to matter.  My vi was written in Labview 8.2.1 with Internet toolkit.  I read in the forum about some limitation of the telnet read problem of the vi from the internet toolkit,  Is there any better read driver around?
    Thanks,
    Patrick 

    Hey!  I have a few questions for you that should help us solve this problem.  First, have you tried out the telnet shipping example "Telnet Line Client.vi".  This will help us minimize programming errors, etc.  Also, what type of device are you trying to communicate with?  Are there other forms of communication available?  For example, does the device also have a serial port, GPIB Port, etc.?  Also, is it possible to write to the device using TCP/IP (This is what telnet is based on)?  Let me know the answers to these questions and I will be better equipped to help you out!!
    Thanks!
    Dan
    Daniel Eaton
    National Instruments
    Systems Engineering
    Embedded and Industrial Control

  • T 420s cooling air coming out is very hot, finger print reader problem

    I am living in ruwais, abudhabi.i bought T 420s in last June from LENOVO  authorized distributor. Model number is 4174-KK4 and the sr no ***.
    Sometime the cooling air coming out is very hot, unable to keep the laptop on the lap.
    The cooling fan also replaced still the temperature is high.
    After replacing the fan I noticed that I noticed one of the screws was not fixed, I asked them to fix it, then they fixed it.
    I traveled back to my home 240 KM from the  authorized distributor service  center. when I started the laptop, the fingerprint reader was not working . Then I traveled back 240 KM to the  authorized distributor service  center to fix the issue. They fixed the fingerprint reader problem.
    Then now the SD card reader is not working. I was asked to bring the laptop to the  authorized distributor service centre.
    Can any one experience the same type of problems  with T 420s the cooling air coming out is very hot, finger print reader problem, card reader not working?
    The authorized distributor says for the service they can only cover 50 KM form the  authorized distributor service  center to the customer point, what is the conditions for the On site warranty ?. I am living 240 KM away from the authorized distributor service center from whom I bought the laptop.
    Moderator comment: Serial number(s) removed to protect member from mischief.

    Well clearly after the first incident. You need to check and us it verifying everything is working before leaving the service center or town its in. Go to a coffee shop and spend time using it and test each option is working.
    When the notebook its opened the finger print reader, card reader etc may not be connect properly or connectors not snap fully and disconnect. Mouse ultranav I have heard may also. But clearly you assume too much and you need to spend the time testing its working before leaving.
    These service center are only paid a fixed amount so they won't spend anymore time then they have to and address one problem you brought it in for.
    As for heat out put and over heating. There are many threads on these systems you can find and read about.
    Advice:
    - install Core Temp, this will monitor and display on the task bar you CPU core temp and you can see CPU load & Temperature at a glance if it approaching or staying near the max levels which will kill the CPU and/or motherboard due to cooking it. Its free just be sure to deselect any additional software from installing during the process. I use it on my notebooks. If the system is running high core Temp all the time you need to have it resolved or it will die and most likely out of warranty and/or your data will be lost if you don't have a backup as well. http://www.alcpu.com/CoreTemp/
    - use a laptop cooler. Its a flat pad you sit the laptop on you lap or table with usually two cooling fans that plug into the USB port for power. It will help cool the base of the laptop and other components inside will not be as hot. This will do nothing for the CPU temperature though.
    T520 Model 4239 Intel(R) Core(TM) i7-2860QM CPU @ 2.50GHz
    Intel Sandy Bridge & Nvidia NVS 4200M graphics Intel N 6300 Wi-Fi adapter
    Windows 7 Home Prem - 64bit w/8GB DDR3

  • I am unable to print documents.  States Adobe reader problem

    I cannot print documents as it says Adobe reader problem or error

    Windows 7; HP 2009m; printer is Lexmark S415;
    Message says
    Acro RD32.exe
    Adobe PDF document
    (There is a problem with Adobe Adrobat/Reader.  If it is running, please
    exit and try again. (15:3)

  • DataSocket Read problem

    Hi all,
    When I use the new condensed "DataSocket Read" vi in Labview 6i (which is
    unfortunately not editable and is supposed to replace old vi's like "open
    connection", "update", "close" and so on) a single time to read automat
    words through an OPC server, the vi returns "zeros" all the way. The only
    solution I found to read the right datas is to place the "DataSocket Read"
    in a "While Loop" which loops until datas are different from zeros, which
    is very inconvenient and time consuming. I tried diffferent settings with
    "DataSocket Read" (wait for update, timeout) but the problem remains.
    Have you also faced the same problem ? Is there a solution ? Thanks for your
    assistance.
    Gaël RENEVIER
    Responsable Maintenance & Développement
    Tél : 04 74 82 20 08
    Fax : 04 74 82 24 92
    e-mail : [email protected]

    This is a problem with the 6i data socket routines ... use the old routines
    from the data socket examples (with the open,update, close drivers), and it
    works fine.
    Dave Gianetto
    http://www.gianetto.org
    > From: [email protected]
    > Organization: UUNET
    > Newsgroups: comp.lang.labview
    > Date: Tue, 21 Nov 2000 16:05:38 +0100
    > Subject: DataSocket Read problem
    >
    > Hi all,
    >
    > When I use the new condensed "DataSocket Read" vi in Labview 6i (which is
    > unfortunately not editable and is supposed to replace old vi's like "open
    > connection", "update", "close" and so on) a single time to read automat
    > words through an OPC server, the vi returns "zeros" all the way. The only
    > solution I found to read the right datas is to place the "DataSocket Read"
    > in a "W
    hile Loop" which loops until datas are different from zeros, which
    > is very inconvenient and time consuming. I tried diffferent settings with
    > "DataSocket Read" (wait for update, timeout) but the problem remains.
    >
    > Have you also faced the same problem ? Is there a solution ? Thanks for your
    > assistance.
    >
    >
    > Gaël RENEVIER
    > Responsable Maintenance & Développement
    > Tél : 04 74 82 20 08
    > Fax : 04 74 82 24 92
    > e-mail : [email protected]
    >
    >

  • Card Reader problem with MSI K8T Neo

    Hi,
    I have the K8T Neo motherboard, and every once and a while my Atech Flash 9 in 1 card reader  (http://www.newegg.com/app/ViewProductDesc.asp?description=20-176-003&depa=0) doesn't power up, thus I can't use it.
    What's odd is that all my other USB devices work flawlessly.
    The only way I'm able to use the card reader again is to power down my computer and then flip the power switch on the psu, then turn it back on, or unplug the reader from the usb header on the motherboard and plug it back in.
    I've noticed other people have had similar issues...
    Any ideas what causes this, or any ideas on how to fix this?
    Bio Haz

    Yes, I had the same hanging problems as well with older BIOS versions then 1.7.
    But that isn't the problem I'm talking about, the computer always starts up, it's just a matter if the usb reader will work or not.
    Maybe MSI has yet to make a BIOS that is compatible with all card readers.
    BioHaz
    Quote
    Originally posted by me_AMD
    ...yes, I had USB card reader problems but it caused the computer to hang during POST, and that was fixed with BIOS v1.7...
    ...I've had what you describe happen on another machine with a Mitsumi card reader/floppy drive combo...not sure what caused it...had to disconnect it and then plug it back in...???...

  • Message reader problems after Microsoft Apps insta...

    My previous thread was delete due to forum rules infringment.
    I describe here again my problem, hoping to have a solution and considering that the problem I faced was not my fault, but it happened after a Nokia official update downloaded via Ovi Suite.
    On 15th of April I've installed the Microsoft Apps and after my C6-01 reboot I found that the application "message reader" does not work anymore (tapping on the blue icon in the homescreen had no effect).
    The only way to use the message reader was going in the incoming SMS folder, select a message anoose "LISTEN" from the menu. In this way the reader works.
    Some days ago someone in this forum suggested me to remove the configured mailbox and try; in this way the reader came back to life and worked again, but if I add a mailbox the problem come back and the reader is malfunctioning again. So the only way to have this application working is removing any mailbox from my C6-01.
    Therefore, considering that this problem occurred after an official update from Nokia and not for an user's error, I would like that Nokia tell me how to solve this malfunction.
    Thanks for your attention and forgive my poor english.

    After the first time I installed Micro$oft App$ I did a deep reset pressing the four keys as described in a web site I've found. After this procedure my C6-01 rebooted without many applications, so I have connected it to Ovi Suite and restored the firmware. The result was a "brand new" and perfect phone, until the new installation of M$ Apps on 11th of April :-(
    So we are three Nokia users with the same problem... and we will faithfully wait for a fix ;-)

  • Hp officejet pro 8600 multi-card reader problem

    Have officejet 8600 printer/fax with multi-card reader.  All worked fine when wired to Apple computer before. Went wireless last week...set up router etc. All worked fine till I tried to load an sd camera card in the printer like i had done many times before.  Doesn't recognize the multi-drive...all lights start to flash..tells me i need to turn printer off/on to continue....NEVER does recognize the card reader!...
    I remember there was an update from Apple that had to do with printer drivers on Oct.15th....could that be the problem or do I need to set something else because of the wireless setup? 
    The printer works fine otherwise....it does recognize the wireless connection for straight printing. I haven't tried the fax part yet.

    Hi lincon50
    I understand the memory card isn't being recognized since the wireless setup and the apple update.
    Please take a look at the post from pcwizard and give it a try.
    http://h30434.www3.hp.com/t5/Other-Printing-Questions/transferring-photos-from-memory-card-to-comput...
    Here is a url for memory card troubleshooting.
    I would test the memory card in another device.
    http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&lc=en&docname=c00059994#N824
    If you need more assistance just let me know.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • Adober reader problem with printing a PDF

    I instaleed Adobe reader on a new computer w/o problem. I could open a view documents. When I go to print I get a message that says: "Adober Reader has stopped working" I can then check one of two boxes: 1. Checkonline for a solution later and close program or 2. "Close program"
    I'm baffeled - all i want to do is print a PDF doc??

    Hi,
    We have provided the permanent fix for this issue. please refer http://kb2.adobe.com/cps/928/cpsid_92870.html.
    Thanks,
    Atul Agarwal
    Adobe Systems

  • Windows 7 64-bit: Switchable graphics and Ricoh card reader problem

    Hi guys,
    Two problems with my laptop. I'm using a T400, previously installed with Windows Vista Business 32-bit.
    Switchable graphics worked well until I formatted and installed Windows 7 Pro 64-bit (I got the RTM through MSDNAA). Now, Windows can only detect either the discrete graphics or integrated graphics at one time. When the BIOS was set to switchable graphics and enabling the detection of switchable graphics on Windows, it could only detect the Intel integrated graphics. When I try to switch to High Performance graphics through the Lenovo power manager, the screen flashes once, and the ATi graphics card appears on the device manager with the code 10 error (cannot start device). Also, compared to this image, my power manager window that opens with left-click does not have battery stretch and switchable graphics options. I have to right-click to switch my graphics.
    After some tinkering, I managed to activate the graphics card through the BIOS by switching it to discrete graphics only and disabling switchable graphics detection by Windows. Now the device manager shows the ATi card only, the Intel integrated graphics is gone. I understand that it should show both display adapters in the device driver when the ATi card is active: http://www-307.ibm.com/pc/support/site.wss/MIGR-70495.html#g4
    The second problem is with the Ricoh card reader. I managed to install the drivers properly, but the device shows up with a code 12 error (This device cannot find enough free resources that it can use) in the device manager. That error appears on 6 items in the device manager:
    Ricoh Memory Stick controller
    Ricoh SD/MMC Host controller
    Ricoh xD-Picture card controller
    Ricoh 1394 OHCI Compliant host controller
    Ricoh R/RL/5C476(II) or Compatible CardBus controller
    SDA Standard Compliant SD host controller
    Additionally, 6 error messages appear during every boot up, which I think is related to these 6 devices:
    ERROR
    Resource Conflict - PCI in slot 07
    Bus:15, Device:00, Function: 00 (it ranges from function 00  to 05)
    AND disabling the device through device manager results in a BSOD.
    I've seen some people post about the Ricoh problem, but didn't have any resolution (at least for those who had the boot up error message too). The switchable graphics problem seems quite common too but in my case it seems like it is working fine EXCEPT for the fact that only one graphics adapter can appear on the device manager at one time and I can't do switching at all. Anyone know if I can somehow solve this? Sorry for the wall of text and two-problems-in-one. I put them together because I don't know if one problem is affecting the other as both problems appeared at around the same time.

    As far as the graphics goes it's well accpeted the only way at present to switch is though the bios manually. There is currently no drivers that enable users to switch from within Win7. Know it's a pain but will just have to wait.

  • Starting Reader problem (edited by host)

    Shortly after opening Adobe reader a window pops up and says, "were sorry Adobe reader has encountered a problem and needs to close".  What can I do to fix this problem??

    If you are running Windows try disabling protected mode.

  • Adobe reader problem on viewing PDF file created by crystal report

    I have a VB6 application to export the PDF file by using crystal report 9. However, when I viewed the PDF file under Adobe reader 8, I have a following message when I hit the page down key.
    "An error exists on this page. Acrobat may not display the page correctly.
    Please contact the person who created the PDF document to correct the problem."
    After hit okay, this message will be gone and I can see the PDF file without problem. However, I don't have this issue when using Adobe reader 5 or 6 version.
    If I crystal report 11 version to export the PDF, everything works fine also but our production machine can only use crystal report version 9, not 11.
    Anyone have idea?? Thx!

    Sounds as if there is a bug in the older version of Crystal reports.
    If you are prevented from installing fixes for bugs, you may well be
    stuck with the effect of the bug.
    Aandi Inston

Maybe you are looking for

  • How to Block the GRN,

    Dear Experts                    How to block the GRN, to avoid the excess inventory for the particular  material.

  • Filter data in multiple tabs from same XMLDataSet

    Hi All: What I need to do is display the content from one XML file in several different modes. I would prefer to use only one data call if possible because all information exists in the one file; however, I have not yet found a way to successfully fi

  • Premiere missing from creative cloud

    I downloaded the Trial for the Creative Cloud and I don't see Premiere. Every time I try and download Premiere it downloads Creative Cloud all over and it still doesn't show Premiere.

  • Refurbisment order and COPA

    Hi I would like to know when and how costs of refurbisment order are taken into account in COPA. Below our process : 1/ Buyback of a machine X1 in plant FR02 (50ku20AC) 2/ Transfer of X1 from FR02 to plant FR01 (50ku20AC) A refurbishment order is cre

  • Is it possible to post a good issue movement before post the good receipt

    Is it possible to post a good issue movement before post the good receipt  movement for the same material, into the same period? We try to explain better, today we've done a test: Step 1 :   We have created a material, wich material type is HAWA, wit