Kotlin – How to read File with Kotlin language
Kotlin
104
file
2
read
6
Male avatar

loveprogramming viết ngày 07/05/2021

https://grokonez.com/kotlin/kotlin-read-file-kotlin-language

Kotlin – How to read File with Kotlin language

This tutorial shows you how to read File in Kotlin using InputStream or BufferedReader.

I. Technology

  • Java 1.8
  • Kotlin 1.1.2

    II. Overview

    1. Goal

    Read file: all lines/by line using InputStream or BufferedReader or File directly.

    2. Steps to do

  • Create:
  • InputStream from File, then get BufferedReader using bufferedReader() method
  • BufferedReader from File.
  • Use:
  • Closeable.use() method with Reader.readText() method inside block. Closeable.use() will automatically close the input at the end of the lambda's execution:
    
    String = (Reader implements Closeable).use(Reader.readText())
    
  • Reader.useLines() method with Kotlin Sequence (a sequence of all the lines) inside block. Reader.useLines() will automatically close the reader once the processing is complete:
    
    Reader.useLines(block: Sequence)
    
  • File.useLines() method with Kotlin Sequence (a sequence of all the lines) inside block. It will close the reader once the processing is complete:
    
    File.useLines(block: Sequence)
    
  • File.readLines() method to return a List<String>:
    
    File.readLines()
    

    III. Practice

    0. kotlin.txt

More at:

https://grokonez.com/kotlin/kotlin-read-file-kotlin-language

c

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

545 bài viết.
97 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 11 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 9 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 9 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/kotlin/kotlinreadwritecsvfileexample How to read/write CSV file in Kotlin In this tutorial, we're gonna look at examples tha...
loveprogramming viết 5 tháng trước
0 0
Male avatar
0 0
https://grokonez.com/kotlin/kotlinreadwriteexcelfileapachepoiexample Kotlin – How to read/write Excel file with Apache POI In this tutorial, we'r...
loveprogramming viết 5 tháng trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
545 bài viết.
97 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!