When I changed the application.properties file to UTF-8 in Eclipse,
If you get it below, the characters will be garbled.
Is there a way to get it without garbled characters?
ResourceBundle=ResourceBundle.getBundle("application");
String test = bundle.getString("test");
★Application.properties is as follows
test=test.
I tried this, but it didn't work...
ResourceBundle=ResourceBundle.getBundle("application");
String test = null;
test = bundle.getString("test");
test = new String(test.getBytes("ISO-8859-1"), "JISAutoDetect";
Also, the Eclipse setting is
US>Window->General->In Content Type
Default java property file encoding is UTF-8.
I think it is possible to do so as described on the above site.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
public class ResourceBundleUtf8Control extensionsResourceBundle.Control{
@ Override
public ResourceBundle newBundle(final String baseName, final Locale locale, final String format,
final ClassLoader loader, final boolean reload)
flowsIllegalAccessException, InstantiationException, IOException {
final String bundleName = to BundleName(baseName, locale);
final String resourceName=toResourceName(bundleName, "properties");
try(InputStream is=loader.getResourceAsStream(resourceName);
InputStreamReader isr=new InputStreamReader(is, "UTF-8");
BufferedReader reader = new BufferedReader(isr)) {
return new PropertyResourceBundle (reader);
}
}
}
Define a class similar to the one above, and use it in the following ways:
ResourceBundle=ResourceBundle.getBundle("application", newResourceBundleUtf8Control());
In addition, since Java9 has the default encoding of ResourceBundle to UTF-8, you don't need to use the above method.You can retrieve the code exactly as expected in the questionnaire.
ResourceBundle=ResourceBundle.getBundle("application");
System.out.println(bundle.getString("test"));
However, I was concerned that the file name was application.properties
.Is that really a resource bundle?
For example, if it is the Spring Boot configuration file, it should be treated with ISO 8859-1 instead of converting Java 9 or later to UTF-8 because it is not a resource bundle but just a property file.
The input stream is a simple line-oriented format specified by load (Reader) and is assumed to use ISO 8859-1 character encoding.In other words, each byte has one Latin character. Characters that are not present in Latin 1 and some special characters are represented using Unicode escapees defined in Section 3.3 of Java™ Language Specifications within keys and elements.
In fact, Spring Boot treats application.properties
as such:
If you want the ISO 8859-1 encoded property file to be displayed on Eclipse as expected (so that you can read Japanese), you may be able to use the following plug-in:
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
581 PHP ssh2_scp_send fails to send files as intended
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.