Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7735217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:26:43+00:00 2026-06-01T07:26:43+00:00

I want to send more than one image file from client to server for

  • 0

I want to send more than one image file from client to server for this I write the code in my application, but it will send only one image.
In client application one frame is there and in server application also there is a frame to start/stop the server.

One more problem is there when Client application send the image file then this image file shown on server computer but when I try to open this image file then nothing is there but when I close server application(server frame) then I am able to see the image.

code:

client site:

public void sendPhotoToServer(String str){ // str is image location
    try {
        InputStream input = new FileInputStream(str);
        byte[] buffer=new byte[1024];
        int readData;
        while((readData=input.read(buffer))!=-1){
        dos.write(buffer,0,readData); // dos is DataOutputStream
        }
    } catch (FileNotFoundException e) {

    } catch (IOException e) {

    }       
}

In server side this code is running into thread:

public void run() {
while (true) {
            try {
                byte[] buffer = new byte[8192];
                fis = new FileOutputStream("C:\\"+(s1++)+".jpg"); // fis is FileOutputStream
                while ((count = in.read(buffer)) > 0){ //count is a integer and 'in' is InputStream
                fis.write(buffer, 0, count); 
                fis.flush();    
                }
                } catch (Exception e) {}
}
}

Problem:

  1. only 1st image is copying which is send by the client.
  2. I am able to see this Image only when I close the server application.

no exception is there and i call sendPhotoToServer method in other class consecutively to send all the image file as:

if (photoSourcePath != null) {
                            clientClass.sendPhotoToServer(photoSourcePath+"\\"+rowData.get(5));
                        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:26:45+00:00Added an answer on June 1, 2026 at 7:26 am

    Your server side should stop the thread when its job is done. The while loop just keeps running forever and keeps the stream open (that’s why you see the image when you shut down the server, the threads only stops then).

    Try changing the server side to this:

    public void run() {
        boolean processing = true;
        while (processing) {
            try {
                byte[] buffer = new byte[8192];
                fis = new FileOutputStream("C:\\" + (s1++) + ".jpg"); // fis is
                                                                      // FileOutputStream
                while ((count = in.read(buffer)) > 0) { // count is a integer
                                                        // and 'in' is
                                                        // InputStream
                    fis.write(buffer, 0, count);
                    fis.flush();
    
                }
                processing = false;
            } catch (Exception e) {
                processing = false;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I pass more than one parameter from jQuery to an ASHX file.
i want to send more than one parameter to servlet through anchor tag .
In my application i want send a email to one account.in one button click
Want to send the text from my current vb application to the Active Window
I want to send SQL server Dashboard & Health Report to my client on
I want to implement chat feature in my android application,in this feature one user
What is the best way to implement server push for more than one thing.
I want send a email by Email Class in codeigniter with gmail, but i
Hello Sir i want send list of data to php server i use following
I want to send a xml file to my wcf service , how can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.