VM file storage in velocity-1.7
Demo:
Public Class App_example1 { Public App_example1 () {string propfile = "Velocity. properties" ; String vmfile = "App_example1.vm" ; Velocity. INIT (propfile); velocitycontext Context = New Velocitycontext (); context. Put ( "Games" , Getgamesinfo (); Template = Null ; Template = Velocity. gettemplate (vmfile); bufferedwriter BW = New Bufferedwriter ( New Outputstreamwriter (system. Out); template. Merge (context, BW ); Try {BW. Flush (); BW. Close ();} Catch (Ioexception e) {e. printstacktrace ();}} Private List <string> Getgamesinfo () {list <String> List = New Arraylist <string> (); List. Add ( "War3" ); List. Add ( "Red alarm" ); List. Add ( "CS" ); List. Add ( "QQ Games" ); Return List ;} Public Static Void Main (string [] ARGs) {app_example1 app = New App_example1 ();}}
Analysis of VM file storage location:
The fileresourceloader. getresourcestream (string) method of velocity only searches for VM files in the root directory of the project. The parameter of this method is the VM file name.