# Kotlin copy file

**URL:** <https://discuss.kotlinlang.org/t/kotlin-copy-file/7034>\
**Category:** Android\
**Created:** [March 13, 2018, 4:27pm UTC](https://discuss.kotlinlang.org/t/kotlin-copy-file/7034 "2018-03-13T16:27:59Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Eliote](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/eliote/32/7934_2.png) [@Eliote](https://discuss.kotlinlang.org/u/Eliote)\
**Post date:** [March 13, 2018, 4:51pm UTC](https://discuss.kotlinlang.org/t/kotlin-copy-file/7034/4 "2018-03-13T16:51:04Z")

</div>

You can’t assing a variable during expression in kotlin (take a look at: [Assignment not allow in while expression?](https://discuss.kotlinlang.org/t/assignment-not-allow-in-while-expression/339))

Try that:

```auto
var length = inStream.read(buffer)

while (length > 0) {
	outStream.write(buffer, 0, length)
	length = inStream.read(buffer)
}

```

---

_[View the full topic](https://discuss.kotlinlang.org/t/kotlin-copy-file/7034)._
