Java Read properties file encountered two problems
1. The value of the key in the resource file is too long, writing is not convenient, need to change lines, if the direct return of the contents of the return is ignored
2. The value of the key corresponding to the resource file needs to be wrapped, if the direct return, the same lose the part of the return
Find the following solutions for the above problems:
1. The content is too long to be changed line splicing/Slash, so/after the contents of the normal display
2. Use/n instead of carriage return if the content itself needs to be changed
Package apistudy; Import java.io.IOException; Import Java.io.InputStream; Import java.util.Properties; public class PropertiesTest2 {public static void main (string[] args) {Properties Properties = new properties (); a try {in Putstream InputStream = PropertiesTest2.class.getClassLoader (). getResourceAsStream ("test.properties"); Properties.load (InputStream); Inputstream.close (); Turn off stream} catch (IOException e) {e.printstacktrace ();} String Key1 = Properties.getproperty ("Key1"); String Key2 = Properties.getproperty ("Key2"); System.out.println (Key1); System.out.println (Key2); } }
Output results:
Where did you take the picture? It ' s so beautiful!
Spring
Hibernate
Ibatis
Velocity
Java
Struts
Attached: contents of Test.properties
Key1=where did you take the picture? /
It ' s so beautiful!
Key2=spring/nhibernate/nibatis/nvelocity/njava/nstruts