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 8506239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:32:22+00:00 2026-06-11T02:32:22+00:00

I am successfully using the HttpURLConnection to upload *.txt files . Now I have

  • 0

I am successfully using the HttpURLConnection to upload *.txt files. Now I have the task to change the program for uploading every filetype. I tried my program with .xls files. The files are placed on the server, but the content isn’t readable.

Like you see here:

ÃÃࡱá>þÿ
Œ¸äÌÌÌS
Sheet1Sheet2Sheet3Worksheets4 $€,þÿ3à…ŸòùOh«‘+’³Ù0Å“8Å’@x„äMicrosoft CorporationMicrosoft Excel@â€Ã¸(º»þÿ3à…ŸòùOh«‘+'³Ù0Ëœ8Å’@x„äMicrosoft CorporationMicrosoft Excel@â€Ã¸(º»@â€Ã¸(º»Ì�á°Ãâ\pMicrosoft Corporation

Here my code snippet:

    HttpURLConnection urlConn = (HttpURLConnection) new URL(testdocumentURL).openConnection(); 
    urlConn.setRequestMethod("POST");
    urlConn.setRequestProperty("X-Method-Override", "PUT");     
    urlConn.setRequestProperty("Content-Type", "text/xml"); 
    urlConn.setRequestProperty("Authorization", "Basic "+ Client.getPassword());
    urlConn.setUseCaches(false);
    urlConn.setDoInput(true);
    urlConn.setDoOutput(true);
    urlConn.setFollowRedirects(false);
    urlConn.setRequestProperty("Slug", "Connectiontest/test.xls"); 
    String write = readFile(test.xls);
    urlConn.setRequestProperty("Content-Length","" + write.length());
    urlConn.getOutputStream().write(write.getBytes("UTF8"));

In my optinion there are 2 ways to solve this problem.

  1. change the output at .write(write.getBytes(“UTF8”))
  2. change the intput

At the moment I read the files like this:

    readFile(String test){
    BufferedReader reader = new BufferedReader(new FileReader(test));
    String line = null;
    StringBuilder stringBuilder = new StringBuilder();
    String ls = System.getProperty("line.separator");

    while ((line = reader.readLine()) != null) {
        stringBuilder.append(line);
        stringBuilder.append(ls);
    }
    reader.close();
    return stringBuilder.toString();
    }

I tried to change the RequestProperty() in this ways:

connection.setRequestProperty("content-type", "multipart/form-data");

or

connection.setRequestProperty("content-type", "application/vnd.ms-excel");

Do somebody know to Upload a .xls file like this? I have to prefere the HttpURLConnector, my boss said. :/

Thanks a lot!

  • 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-11T02:32:24+00:00Added an answer on June 11, 2026 at 2:32 am

    Don’t treat the Excel file as a String. Change readFile to read the file into a byte[] instead, then write that to the connection output stream.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm successfully using assets pipeline for months. Now I would like to load some
I'm successfully using Paypal Express Checkout in a marketplace web app passing for every
I am successfully using Eclipse with emulators. Now I want to use my Defy
All these years i have been successfully using EnumServicesStatus in combination with OpenScManager (with
I have been successfully using my code with the javascript library in the ANTLR
I am sending emails successfully using following code. But now I want to attach
For a few months I have been successfully using David Justices Default Button example
I've been successfully using bitmap indexes for years in Oracle environment. Now I'm working
i have parsed data successfully using sax parser and output is coming properly in
I'm successfully using a redirect-action for one of my struts2 mapping files as follows:

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.