Read files contents on the LocalFileSystem

#1

I have a file on my local file system (docker).
How do I read data from it, e.g. S3.readObjs(“file:///data_load/myDirectory/myFile.csv”) ?

0 Likes

#2

I think you should be able to do this with the LocalFileSystem type, in particular the openFile method

0 Likes

#3

If you want to read the whole file as a string, you can do
File.readString(“file:///data_load/myDirectory/myFile.csv”)

0 Likes

#4
FileSystem.fromUrlOrEncodedPath(<url>).makeFile(<url>).readObjs({serType: <Type>})
  • fromUrlOrEncodedPath will detect the filesystem from the url
  • makeFile makes a file instance of the corresponding filesystem
  • readObjs needs a FileObjsOperSpec to specify the serialization for reading instances of the type.
    You can also use readString, but be careful if the file is very huge readString alone might blow up and you need to specify the start and end index… something like
S3File.make(<url>).readString(0,100)
1 Like