“Unmappable character for encoding UTF-8” error

后端 未结 10 821
失恋的感觉
失恋的感觉 2020-11-27 03:21

I\'m getting a compile error at the following method.

public static boolean isValidPasswd(String passwd) {
    String reg = \"^(?=.*[0-9])(?=.*[a-z])(?=.*[A-         


        
10条回答
  •  爱一瞬间的悲伤
    2020-11-27 03:39

    For IntelliJ users, this is pretty easy once you find out what the original encoding was. You can select the encoding from the bottom right corner of your Window, you will be prompted with a dialog box saying:

    The encoding you've chosen ('[encoding type]') may change the contents of '[Your file]'. Do you want to reload the file from disk or convert the text and save in the new encoding?

    So if you happen to have a few characters saved in some odd encoding, what you should do is first select 'Reload' to load the file all in the encoding of the bad characters. For me this turned the ? characters into their proper value.

    IntelliJ can tell if you most likely did not pick the right encoding and will warn you. Revert back and try again.

    Once you can see the bad characters go away, change the encoding select box in the bottom right corner back to the format you originally intended (if you are Googling this error message, that will likely be UTF-8). This time select the 'Convert' button on the dialog.

    For me, I needed to reload as 'windows-1252', then convert back to 'UTF-8'. The offending characters were single quotes (‘ and ’) likely pasted in from a Word doc (or e-mail) with the wrong encoding, and the above actions will convert them to UTF-8.

提交回复
热议问题