1

My requirement is to create random data using faker for China country. I am getting ??? for the data generated for CN country using faker.

For other locales like en-US and en-AU the data is generating correctly

Faker faker = new Faker(new Locale("zh","CN"));
faker.name().firstName() - output: ???
faker.address().streetName() - output: ???
faker.address().cityName() - output: ???

Can anyone help me with this issue please.

Thanks in advance

user2852305
  • 173
  • 3
  • 14

1 Answers1

2

Based on some limited research (a brief look at the source code on github), the JavaFaker library does support Locale("zh","CN").

So, I think that the real problem here is the way that your JVM is handling the output.

For example, if your JVM is running with LATIN-1 (or another 8bit European character set) as the default text encoding, then it will translate Chinese characters into ? ... which is the substitution character for codepoints that cannot be represented.

  • If your console is capable of rendering Unicode (UTF-8) and you have Chinese fonts installed, try changing the console's default character encoding to UTF-8.

  • If your console is already set up for UTF-8, check what System.getProperty("file.encoding") is set to.

  • Read this Q&A about changing the default encoding that Java uses:

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216