We have a text file with extended ascii (words like 'Systèmes' and 'Café'). It is in Google Cloud Storage. Its Content-Type is text/csv. If I download it via the browser UI (https://console.cloud.google.com/storage/browser/...) all of the characters are correct. However, If I download it from java, using the code below, I get crap for each of the extended ascii characters.

    Blob blob = storage.get(blobId);
    String fileContent = new String(blob.getContent());
    List lines = new ArrayList(Arrays.asList(fileContent.split("\\r?\\n")));

The file is, I believe, UTF-8 encoded. Thanks!

  • 1
    Welcome to Software Engineering. We only support good, on-topic questions. Many sites have different rules. Feel free to take your issue to an appropriate site if one exists. Search existing answers first. Edit your question to fit the sites needs. Please don't cross post by failing to delete your question here. – candied_orange Oct 11 '19 at 1:51

Sigh - the problem was not with GCS at all. Instead of:

String fileContent = new String(blob.getContent());

I need to use:

String fileContent = new String(blob.getContent(), Charset.forName("UTF-8"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.