Guest User

Untitled

a guest
Apr 30th, 2018
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import android.os.Bundle
  2. import android.support.v4.app.Fragment
  3. import android.view.LayoutInflater
  4. import android.view.View
  5. import android.view.ViewGroup
  6. import android.widget.Button
  7. import supe.epic.exepmple.R
  8. import java.io.*
  9.  
  10.  
  11.  
  12.  
  13.  
  14. class Fragment7 : Fragment(), View.OnClickListener {
  15.  
  16.  
  17. override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
  18. savedInstanceState: Bundle?): View? {
  19.  
  20. val btn: Button? = view?.findViewById(R.id.btn)
  21. btn?.setOnClickListener(this)
  22. return inflater.inflate(R.layout.frgmnt7, container, false)
  23. }
  24.  
  25. fun copy() {
  26. val bufferSize = 1024
  27. val assetManager = context!!.assets
  28. val assetFiles = assetManager.list("")
  29.  
  30. assetFiles.forEach {
  31. val inputStream = assetManager.open(it)
  32. val outputStream = FileOutputStream(File(context!!.filesDir, it))
  33.  
  34. try {
  35. inputStream.copyTo(outputStream, bufferSize)
  36. } finally {
  37. inputStream.close()
  38. outputStream.flush()
  39. outputStream.close()
  40. }
  41. }
  42. }
  43.  
  44. override fun onClick(v: View?) {
  45. copy()
  46. }
  47. }
Add Comment
Please, Sign In to add comment