Le code principal, Kotlin écrit
paquet baise importation com.google.gson.Gson importation java.io.File importation java.sql.Connection importation java.sql.DriverManager importation java.sql.Statement fun principales (args: Array <String> ) { si (args.size <2 ) { println ( "Utilisation: java -jar xxx.jar dbFilePath OutputPath" ) return } val dbFilePath = args [0 ] val savePath = args [1 ] qu'initdb (dbFilePath) getPlayLists () ? .foreach {PLAYLISTS -> getSonsByPid ("$ {} playLists.id")? .foreach { val fromJson = Gson (). fromJson <JsonRootBean> (it, JsonRootBean :: classe .java) arts var = "" pour (ligne fromJson.artists) { arts + = line.name + "" } val path = "$ {$ savePath playLists.name.replace (" / " "-")} txt." fichier (savePath) .mkdirs () fichier (chemin) .appendText (fromJson.name + "-" + arts + "\ n" ) } } closeDB () println ( "导出完毕" ) } Var c: Connexion ? =null var stmt: Déclaration ? = Null plaisir qu'initdb (dbFilePath: String) { Class.forName ( "org.sqlite.JDBC" ) c = DriverManager.getConnection ( "jdbc: sqlite: $ dbFilePath" ) stmt = c? .createStatement () println ( "base de données ouverte avec succès" ) } getPlayLists fun (): Liste <PlayListBean>? { Val rs = stmt .executeQuery ( "SELECT playlist DE web_playlist;"):? Retour null val pid = mutableListOf <PlayListBean> () tout en (rs.next ()) { pids.add (. Gson () fromJson (rs.getString ( 1), PlayListBean :: classe .java)) } return pid } amusant getSonsByPid (pid: String): Liste <String>? { Val sql = "SELECT de piste web_track OÙ tid dans" + "(SELECT tid de web_playlist_track OU pid = '$ pid');" chansons val = mutableListOf <String> () val rs = stmt .executeQuery (sql):? retour nul alors que (rs.next ()) { songs.add (rs.getString ( 1 )) } return chansons } amusant (closeDB ) { stmt ? .close () c ? .close () }
Adresse de l'entrepôt