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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:36:32+00:00 2026-05-14T14:36:32+00:00

I’ve written this little test class to connect up to an FTP server. import

  • 0

I’ve written this little test class to connect up to an FTP server.

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class FTPTest {

    public static void main(String[] args) {
        URL url = null;

        try {
            url = new URL("ftp://anonymous:Password@127.0.0.1");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        URLConnection conn = null;

        try {
            conn = url.openConnection();
        } catch (IOException e) {
            e.printStackTrace();
        }

        InputStream in = null;

        try {
            in = conn.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }

        BufferedInputStream bin = new BufferedInputStream(in);
        int b;

        try {
            while ((b = bin.read()) != -1) {
                char c = (char) b;
                System.out.print("" + (char) b);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Here’s the output:

-rw-r--r-- 1 ftp ftp           4700 Apr 30  2007 premier.java
-rw-r--r-- 1 ftp ftp          88576 Oct 23  2007 Serie1_1.doc
-rw-r--r-- 1 ftp ftp           1401 Nov 21  2006 tp20061121.txt
drwxr-xr-x 1 ftp ftp              0 Apr 23 20:04 répertoire

Notice the name of the directory at the end of the list. There should be an “é” (e with acute accent) instead of the double character “é”.

This reminds me of an issue encountered previously with JSF where there was a mix-up between standards. I have little experience with character-encoding though so I’m not sure what’s happening. I’m supposing that the server output is in ASCII so how do I adapt the output so it appears correctly in the console?

  • 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-05-14T14:36:33+00:00Added an answer on May 14, 2026 at 2:36 pm

    You’re brute-force converting bytes from the input stream into chars using

    char c = (char) b;
    

    This is definitely not the Good Housekeeping approved form.

    Streams deliver bytes, and you want chars. Readers deliver chars and will do character set translation for you in an automatic and controlled way.

    You should wrap an InputStreamReader around the InputStream. The constructor for InputStreamReader allows you to specify a CharSet, which will let you control the translation.

    Reading from the InputStreamReader will of course yield “real” chars. Another benefit is that you can wrap a BufferedReader around the InputStreamReader and then read entire lines at a time (into a String) using readLine.


    EDIT: To illustrate what I mean by “wrap around,” here’s some (untested!) coding to illustrate the idea:

    BufferedReader br = new BufferedReader(new InputStreamReader(bin, "US-ASCII"));
    ...
    String line = br.readLine();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to

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.