public static void main ( String [ ] args ) throws IOException { String s = doc ( svg ( 160 , 200 , rect ( 0 , 0 , 160 , 200 , "fill:red;" ) + svg ( 10 , 10 , 100 , 100 , rect ( 0 , 0 , 100 , 100 , "fill:orange; stroke:rgb(0,0,0);" ) ) + line ( 20 , 20 , 100 , 100 , "stroke:black; stroke-width:2px;" ) + line ( 20 , 100 , 100 , 20 , "stroke:black; stroke-width:2px;" ) + text ( 10 , 140 , "font-family:verdana; font-size:20px; font-weight:bold;" , "Hello world" ) ) ) ; File file = new File ( "demo.svg" ) ; FileWriter w = null ; try { w = new FileWriter ( file ) ; w . write ( s ) ; } finally { if ( w != null ) { w . close ( ) ; } } System . out . println ( String . format ( "File written: %s" , file . getAbsolutePath ( ) ) ) ; // optionally view the just created file if ( args . length > 0 && args [ 0 ] . equals ( "-view" ) ) { if ( ! viewSVG ( file ) ) { System . err . println ( "'-view' not supported on this platform" ) ; } } }
Creates a sample SVG file demo . svg