「Kotlin入門」readAllLines()でテキストファイルを読み込むサンプル
書式
public static List<String> readAllLines(Path path, Charset cs) throws IOException
使用例
import java.io.IOException
import java.nio.file.Files
import java.nio.charset.Charset
import java.nio.file.Paths
fun main() {
val cftPath = Paths.get("C:\\data", "sample.txt")
val cst = Charset.forName("UTF-8")
try {
val cftLine = Files.readAllcftLines(cftPath, cst)
for (s in cftLine) {
println(s)
}
} catch (e: IOException) {
e.printStackTrace()
}
}
import java.io.IOException
import java.nio.file.Files
import java.nio.charset.Charset
import java.nio.file.Paths
fun main() {
val cftPath = Paths.get("C:\\data", "sample.txt")
val cst = Charset.forName("UTF-8")
try {
val cftLine = Files.readAllcftLines(cftPath, cst)
for (s in cftLine) {
println(s)
}
} catch (e: IOException) {
e.printStackTrace()
}
}
import java.io.IOException import java.nio.file.Files import java.nio.charset.Charset import java.nio.file.Paths fun main() { val cftPath = Paths.get("C:\\data", "sample.txt") val cst = Charset.forName("UTF-8") try { val cftLine = Files.readAllcftLines(cftPath, cst) for (s in cftLine) { println(s) } } catch (e: IOException) { e.printStackTrace() } }