Code Monkey home page Code Monkey logo

Comments (2)

JakeWharton avatar JakeWharton commented on May 21, 2024

In Okio, the path is a value which represents just that: the file path. There is no intrinsic information that ties it to a particular file system. This is in contrast to java.io.File which is tied to the system file system, or java.nio.file.Path which is tied to a particular java.nio.file.FileSystem.

If you have a path which represents /tmp/hello.txt and I have the same path, reading the file will (probably) produce different results because we have different machines. The path is the same value, the file system is the system file system on both machines but the machines are different. The path doesn't know that, though, and is likely valid on both (or any) machine.

If you have the path META-INT/MANIFEST.MF and you read it from two different .jar files (using zip filesystem) you'll get different results. The path is the same, but the file system is different. The path doesn't know that, it's valid anywhere since it's just a value.

In your case, you have a path /root/file.txt and you are writing to that on the fake file system instance and then attempting to read it from the system file system (by virtue of first converting it to a File). You are writing in one place and reading from another.

The only time toFile() will return a File that points to the same reference is if you were using FileSystem.SYSTEM.

Another way to think about it is to create two instances of FakeFileSystem. If you write to one and then read from the other you will not see the correct size.

By calling toFile() you are taking the path and passing it to a different system that only knows how to read from the system file system.

from okio.

arturdryomov avatar arturdryomov commented on May 21, 2024

Thanks for the detailed and awesome explanation!

from okio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.