1

Assume that there are two file test.txt and test1.txt in "/" directory.

If the filename is shorter than 4096 bytes the file is exist,otherwise is not exist.

My OS is android and filesystem is ext4.

I want to know the reason behind this.Can someone tell me?

String path = new String(new char[4086]).replace("\0\0\0", "../")
String filename = "/"+path+test.txt
File file = new File(filename);
file.getPath().length(); //return 4095
file.exists(); //return true

String path = new String(new char[4086]).replace("\0\0\0", "../")
String filename = "/"+path+test1.txt
File file = new File(filename);
file.getPath().length(); //return 4096
file.exists(); //return false
javapuzzle
  • 11
  • 5

2 Answers2

2

This could happen due to the path Limit of your file System - what are you using?

(Sorry, this is more like a comment than an answer, but I don't have enough Points to comment on your post...)

Kryptur
  • 745
  • 6
  • 17
  • my filesystem is ext4 – javapuzzle May 01 '16 at 13:58
  • Refering [this](https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits) article from Wikipedia, there is no path-limit for ext4. But for Android this could be a different situation: * There could be encryption on file names * There could just be a different limit for path limit than in "original" ext4 – Kryptur May 01 '16 at 14:09
1

The limits are imposed by the operating system. For example:

I want to know the reason behind this.

Java interacts with the operating system via native libraries, and the native libraries have hard limits on the length of both individual file names and pathnames. Java has to conform to the limits.

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216