public static void writeSourceToFile ( Class < ? > koanClass , String newSource ) { Path currentRelativePath = Paths . get ( "" ) ; String workingDirectory = currentRelativePath . toAbsolutePath ( ) . toString ( ) ; String packagePath = koanClass . getPackage ( ) . getName ( ) ; packagePath = packagePath . replace ( PACKAGE_SEPARATOR , PATH_SEPARATOR ) ; String className = koanClass . getSimpleName ( ) ; File file = new File ( workingDirectory + KOAN_JAVA_PATH + packagePath + PATH_SEPARATOR + className + JAVA_EXTENSION ) ; try { FileWriter fw = new FileWriter ( file . getAbsoluteFile ( ) ) ; BufferedWriter bw = new BufferedWriter ( fw ) ; bw . write ( newSource ) ; bw . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } }
Write source to file .