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

  • Home
  • SEARCH
  • 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 8700981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:17:30+00:00 2026-06-13T02:17:30+00:00

readFile file.html start of the file… *** Exception: file.html: hGetContents: invalid argument (invalid code

  • 0
readFile "file.html"
"start of the file... *** Exception: file.html: hGetContents: invalid argument (invalid code page byte sequence)

It’s a UTF-8 file created with notepad++… how can I read the file in haskell?

  • 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-13T02:17:31+00:00Added an answer on June 13, 2026 at 2:17 am

    By default, files are read in the system locale, so if you have a file using a non-standard encoding, you need to set the encoding of the file handle yourself.

    foo = do
        handle <- openFile "file.html" ReadMode
        hSetEncoding handle utf8_bom
        contents <- hGetContents handle
        doSomethingWithContents
        hClose handle
    

    should get you started. Note that this contains no error handling, the better way would thus be

    import Control.Exception -- for bracket
    
    foo = bracket
            (openFile "file.html" ReadMode >>= \h -> hSetEncoding h utf8_bom >> return h)
            hClose
            (\h -> hGetContents h >>= doSomething)
    

    or

    foo = withFile "file.html" ReadMode $
            \h -> do hSetEncoding h utf8_bom
                     contents <- hGetContents h
                     doSomethingWith contents
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to read file /proc/'pid'/status, using c program. The code is as follows,
When I using the following code to read file: lines=file(data.txt).read().split(\n) I have the following
I am wanting to create a page that can load a property file into
Can I use the PHP code below if the PDF file is not on
Ok, I'm trying to play an HTML audio code on iPad but does not
I'm trying to use the following code to create a zip file from a
My goal is to update the web page with some file. When I edit
The following code is supposed to read an image file and then add the
I have embedded the signed applet in following html page, <input type=hidden name=xmldata id=xmldata
im having a setback, im making an Html page with javascript, and im using

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.