# String(contentsOfFile: filepath, encoding .utf8) doesn't work

**URL:** https://talk.remobjects.com/t/string-contentsoffile-filepath-encoding-utf8-doesnt-work/22325
**Category:** Silver
**Created:** [June 14, 2020, 6:38pm UTC](https://talk.remobjects.com/t/string-contentsoffile-filepath-encoding-utf8-doesnt-work/22325 "2020-06-14T18:38:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![peter1](https://talk.remobjects.com/user_avatar/talk.remobjects.com/peter1/32/13062_2.png) [@peter1](https://talk.remobjects.com/u/peter1)
#### Post date: [June 14, 2020, 6:38pm UTC](https://talk.remobjects.com/t/string-contentsoffile-filepath-encoding-utf8-doesnt-work/22325/1 "2020-06-14T18:38:08Z")

</div>

There seems to be a mismatch between normal Swift coding and Silver when reading files into memory, the following code doesn’t work and gives an error saying

> (E600) Parameter labels do not match. Parameter 1 is labeled “contentsOfFile” but should be unlabeled in call to “init(\_ c: Char, \_ count: Int32)”

> ```
> private func readDataFromCSV(filepath: String)-> String!{
> do {
> var contents = try String(contentsOfFile: filepath, encoding .utf8)
> return contents
> }
> catch {
> print("File Read Error for file \(filepath)")
> return nil
> }
> }
> 
> ```

I’m clearly missing something - any ideas?

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [June 14, 2020, 7:40pm UTC](https://talk.remobjects.com/t/string-contentsoffile-filepath-encoding-utf8-doesnt-work/22325/2 "2020-06-14T19:40:22Z")

</div>

I don’t believe our String type implements `String(contentsOfFile:, encoding)`, at least I int recall ever seeing or implementing that. Is that new?

You can use Elements RTL’s `File.ReadText` API for the same purpose.
