File Writing Issue :-(

Hello Guys,
Im trying to write into a file from a InputStream..For which the code is as followspublic void saveFile(String filename,InputStream inpStr)
try{
InputStreamReader stream=new InputStreamReader(inpStr,"SJIS");     
File tobSavedFile=new File(filename);
FileOutputStream fstr=new FileOutputStream(tobSavedFile);
while (true){
    int d=stream.read();
    if (d==-1) break;
    else
     fstr.write(d);
catch(Exception me){
   me.printStackTrace();
}This code works fine when i pass a Text file as inputstream,But it doesnt work good when i pass a GIF or JPG or ZIP file in inputStream...
For example when i passed a file as GIF which was 1.45KB it resulted in creation of GIF file of just 1.34KB..
Why is this??can any one help me..
Thanks a lot for your patience.
Regds,
Gokul

Don't use an InputStreamReader around your InputStream, it's trying to do text conversion and not supposed to be used for binary data.

Similar Messages

  • File Writing with JSP

    Hi all,
    I'm creating a simple app that gets form data and populates it to a file. I want to make sure that each instance (thread?) is able to write to the file and not throw an exception since the file may be currently open by another instance of the jsp. Now I did basic thread programming in C++ a long time ago, so I'm aware of thread waiting conceptually, but I'm not familiar with the java implementation. Can someone show me some basic syntax on how I would go in essentially putting a lock on the file writing portion of the code.
    Thanx much

    I disagree that you should override anything in Threa, especiially the sleep method.
    What you should do is handle the file writing in a producer/consumer fashion. Have a single class that extends Runnable be the consumer. It handles all the file writing issues. You will run this in its own thread.
    Your JSPs (or other threads) fill in a collection, or some other holder, which informs the consumer to write to the file.
    As a brief example, this is a mini logger type of program. I use a class (LogCenter) to log data put in it from other sources (client1 and client2). For the sake of using newer API, I make use of the java.util.concurrent.BlockingQueue (and java.util.concurrent.LinkedBlockingQueue) to make a thread-safe collection and reporting system for text to come in and out of the logger.
    Note, this is far from production. Just something I whipped up when playing with blocking queues a while ago...
    package net.thelukes.steven.thread.test;
    import java.io.PrintWriter;
    import java.util.concurrent.BlockingQueue;
    import java.util.concurrent.LinkedBlockingQueue;
    public class LoggingCenter implements Runnable {
      private PrintWriter output;
      private BlockingQueue<String> toPrint;
      public LoggingCenter() {
        toPrint = new LinkedBlockingQueue<String>(10);
      public void setOutput(PrintWriter pw) {
        if (pw == null)  {
          if (output != null)
            return; //do not replace output with null
          else //pw is null and output is null
            throw new IllegalArgumentException("Ouput PrintWriter must not be NULL");
        else {
          if (output != null) closeOutput(); //if output exists already, close it.
          output = pw;
      public void log(String text) {
        boolean added = false;
        while (!added)
          try {
            toPrint.put(text);
            added=true;
          } catch (InterruptedException ie) {
            ie.printStackTrace();
            try { Thread.sleep(300L); }
            catch (InterruptedException ie2) { ie2.printStackTrace();}
      public void run() {
        try {
          while (true) {
            printLn(toPrint.take());
        } catch (InterruptedException ie) {ie.printStackTrace();}
      private void closeOutput() {
        output.flush();
        output.close();
      private void printLn(String text) {
        if (output == null)
          throw new IllegalStateException
            ("The Output PrintWriter must be set before any output can occur.");
        output.println(text);
        output.flush();
    package net.thelukes.steven.thread.test;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    public class LoggingTest {
      public static void main(String[] args) throws IOException {
        PrintWriter output = new PrintWriter(
          new FileWriter(new File("log.txt")));
        //PrintWriter output = new PrintWriter(System.out, true);
        final LoggingCenter logger = new LoggingCenter();
        logger.setOutput(output);
        Thread t = new Thread(logger);
        t.start();
        Thread client1 = new Thread(
            new Runnable() {
              public void run() {
                while (true) {
                  logger.log("Client 1: "+System.currentTimeMillis());
                  try {
                    Thread.sleep(1250L);
                  } catch (InterruptedException e) {}
        Thread client2 = new Thread(
            new Runnable() {
              public void run() {
                while (true) {
                  logger.log("Client 2: "+System.currentTimeMillis());
                  try {
                    Thread.sleep(2500L);
                  } catch (InterruptedException e) {}
        client1.start();
        client2.start();
    }

  • PS CS3, Camera Raw 4.6 Update and Nikon D810 NEF File Reading Issue

      Currently Have Photoshop CS3 & Adobe Bridge CS3 2.1.1.9.
    According to Adobe, Camera Raw 4.6 supports Nikon D810 NEF files.  I have downloaded Camera Raw 4.6 Update. When
    I try to open Nikon D810 NEF files, I get Photoshop CS3  error that says
    "cannot complete request your because it is not the right kind of
    document. These NEF files wont open in Adobe Bridge at all.  What am I doing wrong?

    Hey,
    Before I purchased, let me get your thoughts on another option that just occurred to me which involves:
    1)Editing my D810 NEF files in LR 5.6, which I have, then exporting/saving the edited files as JPEGs.
    2) Doing any additional editing, as necessary (i.e. that might require layering or selections..etc) , with the JPEGs  with Bridge or PS CS3. 
    This method wont involve any additional software purchase now.. right?    Am I missing anything.   here?    Since my final output to my customers are JPEGs any way, wont this work?   Will I be at any disadvantage.   Am I missing anything.   here? 
    From: ssprengel <[email protected]>
    To: charles cash <[email protected]>
    Sent: Monday, October 6, 2014 9:49 AM
    Subject:  PS CS3, Camera Raw 4.6 Update and Nikon D810 NEF File Reading Issue
    PS CS3, Camera Raw 4.6 Update and Nikon D810 NEF File Reading Issue  created by ssprengel in Adobe Camera Raw - View the full discussion  
    You can buy it from here:
    http://creative.adobe.com/plans
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at https://forums.adobe.com/message/6795004#6795004
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: 
    To unsubscribe from this thread, please visit the message page at . In the Actions box on the right, click the Stop Email Notifications link. 
    Start a new discussion in Adobe Camera Raw by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • SQL Server 2008 .MDF File attaching issue

    Hy all guys here is big Happy news about the SQL Server 2008 database.mdf file attaching issue on Windows 8.1 and SQL Server 2008
    I found the solution like this
    first you go to the directory of your computer and go to that folder where your database and other files are like
    folder having database and files then > Right click and > security > then give full rights from which user you LOGIN and then apply > ok after that go to SQL Server 2008 > Right Click > run as administrator
    Hurray your problem will be resolve I Resolved my issue too  thanks to providing every solution
    if you guys find solution please give me best regards thanks  

    Hi Farhan-Islam,
    Glad to hear that your issue had been solved by yourself. Thank you for your sharing which will help other forum members who have the similar issue.
    Regards,
    Lydia Zhang

  • Recording File Size issue CS 5.5

    I am using CS 5.5, a Balckmagic Ultra Studio Pro through USB 3.0 being fed by a Roland HD Video switcher. Everything is set for 720P 60fps (59.94) and the Black Magic is using the Motion JPEG compression. I am trying to record our sermons live onto a Windows 7 machine with an Nvidia Ge-Force GTX 570, 16 GB of Ram and a 3TB internal raid array (3 drives). It usually works great but more often now when I push the stop button in the capture window, the video is not proceesed and becomes unusable. Is it a file size issue or what. I get nervous when my recording goes longer than 50 Minutes. Help

    Jim thank you for the response. I have been away and busy but getting
    caught up now.
    I do have all drives formatted as NTFS. My problem is so sporadic that I
    can not get a pattern down. This last Sunday recorded fine so we will see
    how long it last. Thanks again.

  • All of a sudden File compatability issues with IPhoto & digital camera

    Anyone have issues or solutions for solving file compatability issues with IPhoto & digital camera?  Worked okay for years but all of a sudden giving me error messages about file format.  My camera uses Jpeg.

    There is an issue ongoing  between 10.6 and Kodak cameras. Workround: use a USB Card Reader.
    Regards
    TD

  • I am having a file moving issue with Adobe Reader XI

    I am having a file moving issue with Adobe Reader XI on a Windows 7 32bit system. When Adobe reader is set as the default program for PDF files moving files from one directory to another takes over a minute, regardless of the size of the file. When the default handler is set to another program, like Nuance or PDF Creator, this is instant. What in Adobe Reader is causing this and what can I do to speed up file moving? Any help will be greatly appreciated. Thank you.

    I am using Windows 7 home edition and using Internet Explorer 10
    The PDF's are online on websites that I am trying to open.  Both on the site as well as trying in a new window.
    Thank you
    Jeff

  • Windows Update Helps with File Size Issues?

    I'm just wondering if anybody has recently noticed an
    improvement related to the file size issue variously reported
    throughout the forums?
    I ask because our IT folks distributed a Windows update on 2
    days last week and since the application of those updates I have
    not experienced the freakishly large file sizes and the related
    performance issues in Captivate. Unfortunately I don't have any of
    the details of what patch(es) were installed, as it was part of our
    boot script one morning and I didn't even realize it was updating
    until I received the Reboot Now or Later alert.
    Anyway, I was curious because I have experienced significant
    performance improvement since then.
    Rory

    If you are using a remote workflow ... designers are sending off-site editors InCopy Assignment packages (ICAPs) .... then they need to create assignments in order to package them for the remote InCopy user. So there's no need to split up a layout into smaller files or anything.  An assignment is a subset of the INDD file; multiple assignments -- each encompassing different pages or sections -- are created from the same INDD file.
    When the designer creates the assignment, have them turn off "Include original images in packages"; that should keep the file size down.
    Or -- like Bob said -- you can avoid the whole remote workflow/assignment package rigamarole all together by just keeping the file in a project folder in the Dropbox folder on teh designer's local hard drive, and have them share the project folder with the editors. In that workflow, editors open the INDD file on their local computer and check out stories, just as though they were opening them from a networked file server.
    I cover how the InCopy Dropbox workflow works in a tutorial video (within the Remote Workflows chapter) on Lynda.com here:
    http://www.lynda.com/tutorial/62220
    AM

  • Why when I'm trying to reinstall my OS, Tiger 10.4, at 56% at files writing, it shuts off?

    Please someone, help me,
    Why when I'm trying to reinstall my OS, Tiger 10.4, at 56% of the installation, at files writing, it keeps on shutting off?

    Does it feel extra hot on top?
    Are you reinstalling because you had several problems? If so what were they?
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214

  • E4200V2 file corruption issues

    Hello,
    I am getting file corruption issues when doing a file transfer onto the NAS (hard drive plugged into the router). Files are turned into folders while keeping the same filename. It happens occasionally.
    I have firmware: 2.1.39.145204 installed.
    Any remedy for this as it is a very serious problem.

    The only known solution is to call linksys and ask them for a replacement router model that does not contain the bug. See thread link for details.
    http://community.linksys.com/t5/Wireless-Routers/Media-files-changing-to-folder-types/td-p/504192/hi...

  • File writing serialization

    I have to build a web application using servlet and jsp. The user should edit some
    text file (maybe displaying the file fields in a HTML form).
    I need some suggestions about implementing the synchronization on file writing (since different
    users should try to save the same file simultaneously).
    Do some standard pattern exist about this feature ?
    I suppose to do that using a java bean whith application scope shared by the jsp pages. In this bean
    I will implement all write methods using synchronized.
    Any suggestions ?
    Thanks in advance,
    Mauro.

    well, if you have a single method which does the actual file writing, then you make that method synchronized and you'll have no problems. You can build up the data to write in some object at any time and pass that to that method.
    However, that's still going to present problems when users actually modify the file at the same time. Why does every user have to share 1 file?

  • File writing permissions??

    is there any file writing permissions in jsp?
    i can create folders with my code on my localhost Tomcat 5.5.
    but now i have a webhost which has Tomcat 5.0...with my same jsp code i can see the content of my folders but cannot create any new folders under wwwroot or somewhere else on my webhost...
    so i am thinking if it is related with permissions or something like that?please show me a way
    thanks
    Burak

    my host admin responded;
    Hi,
    We can enable write permission, but this will put you in high security risk in tomcat shared hosting, as any other user also from his jsp/servlet script can write anything into your directory or delete file.
    Now what you think?what i want to do is i have a photo album site...users can create their own folders and upload their photo albums...but this users' main folder must be somewhere in a protected area that users musnt directly link to this photos...like before wwwroot or after WEB-INF folder...where can it be?
    please help me in this subject..need really help..
    thanks

  • Does UTL_FIL utility supports file writing in to remote Host ??

    Hi,
    I am checking the possibility with UTL_FIL utility whether supports file writing in to remote Host. My database is on different server from UNIX server but i want to make use of Oracle directory objects or UTL_FILES functions to be able to write files directly from Oracle to remote UNIX server.
    Is this possible ?
    Thanks
    Anand

    UTL_FILE, and any other PL/SQL package running on the database server, can only access objects that the database server has access to. Unless the remote Unix server's file system is mounted from the Oracle server's file system, UTL_FILE would be unable to create a file there.
    Now, there may well be alternateives. For example, you could generate the file locally and FTP the file to the remote Unix server, assuming the remote Unix server is running a FTP server.
    Justin

  • CC application file sync issue and CC App broken menu..

    1. File sync from Photoshop CC has stopped working.
    Photoshop reports the last sync time and date in edit>sync settings.
    However in my Application settings I get the following..
    Application settings are synced between many of your favorite desktop applications and Creative Cloud, allowing you to work consistently from any machine. To begin syncing, you will need to open your desktop application and click "Sync Settings Now".
    You currently do not have any synced settings.
    2. I have missing menu items in the CC app cog menu (I assume as reported on other threads) including "stop syncing", preferences/settings and other blank or greyed out items.
    Prior to that I had the also reported dead CC app issue and uninstalled and reinstalled the app, which fixed dead app but left the munu broken.

    Hallo over there
    After using creative cloud cleaner ....
    every things is ok...8-)
    Sendt fra mobilen....
    Med venlig hilsen/Kind regards
    Fotograf Hans Søndergaard
    Allégade 23  1.baghus
    DK 2000 Frederiksberg
    M: +45 4044 8190
    [email protected]
    www.soendergaard.com
    Den 07/11/2013 kl. 17.32 skrev Simon_P1 <[email protected]>:
    Re: CC application file sync issue and CC App broken menu..
    created by Simon_P1 in Adobe Creative Cloud - View the full discussion
    Since the CC app messed up again and yet another reinstall, it is working (sort of, after several sync failures of lrcat) properly, including the menu, all be it very slowly considering the fast upload I have.
    As is the setting sync finally.
    Thanks for keeping me informed, oh wait, you didn't!
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5823499#5823499
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5823499#5823499
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5823499#5823499. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Adobe Creative Cloud at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • DMS Original File Display issue

    Hello All,
    This is regarding Original File dispaly issue in DMS. User is using CV04N transaction to download the file. After going in the DMS screen user is selecting the file, Right Click & select the option "Copy to". Then user select the option to save the file on Desktop. If required user change the description of the file & save it on Desktop.
    But when he tries to open that file from the desktop, file is not diaplayed & does not give any error. In some cases file is taking more than 10 mins to open the file.
    This issue is faced by only two users whereas on my laptop file is displayed properly without any issue.
    What could be the reason behind this? Waiting for your valuable reply.
    Thanks
    Pravin

    Hi,
    As it happens after saving the file it si probably the local system issue.Please check if the application is not corrupt or you are using the latest version of the same.
    Thanks
    Amulya

Maybe you are looking for

  • How to remove an iphone from my id

    hi, once my friend sync-ed his iphone with my computer. then whenever he is in wi-fi zone it is asking password for my used id for updating the apps. how to change the user name in his phone or how to remove his device from my apple ID. please help.

  • Is it possible to create sharepoint 2010 Project in VisualStudio, if yes then kindly tell how?

    I have try to create sharepoint 2010 Project in VisualStudio 2012. but give me error A Sharepoint server is not installed on this computer.A sharepoint server must be installed to work with sharepoint Project.

  • Module pool in report

    hai abapers, i am having a requirement of a report which i have to call it thru transaction. this report screen no. 1000 should be assigned to the transaction, after that i need to call another module pool screen basing on the values in the screen 10

  • Does Portal support syndicated content?

    My users would like to be able to push syndicated content out to various client's portals (or web sites) while maintaining control over that content. I recall reading that such support would be provided in a later release ( i.e. 9i time frame) via Co

  • How to open an internet browser inside an Oracle Form?

    Hello, I am using Oracle forms 10g and I want to open  any internet browser inside my oracle form. Any idea if it is even do able in the forms. Thanks in advance for your help! Hemangi