Search code examples
scalaapache-sparktemp

check if the temporary file(semaphore) exists using scala


how can I read(check) a temp file created on my system please.

I need to check if a temp file exists or not using scala,

how can i do this.


Solution

  • Try this:

    import org.apache.hadoop.conf.Configuration
    import org.apache.hadoop.fs.{FileSystem, Path}
    
    val fileSystem = FileSystem.get(new Configuration())
    val path = new Path("/tmp/foo/bar/meow.parquet")
    if (fileSystem.exists(path)){
        // TODO ...
    }
    

    It will work on local, Docker and remote file-systems (S3 & HDFS) fluently

    Hope it helps