0

I have a problem with java and mkdirs.

I would like to create a folder with / in its name like: C:\Sun/Moon\

String pfad = projektnummer;
if (!kunde.isEmpty()) {
    pfad = pfad + " " + kunde;
}
if (!projektname.isEmpty()) {
    pfad = pfad + " - " + projektname;
}
File ziel = new File("P://" + pfad)
ziel.mkdirs();

The content of kunde can be something like Microsaft/Apple.

At the moment I get a C:\Microsaft\Apple and not C:\Microsoft/Apple\.

Andrew Stubbs
  • 4,322
  • 3
  • 29
  • 48
Garog
  • 315
  • 1
  • 5
  • 15
  • A slash in filenames is not allowed!! – Jens Jul 21 '14 at 09:41
  • Slash are note allowed in file/dirnames. See http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx – Iralution Jul 21 '14 at 09:42
  • `"/"` are not allowed in diretory names on Windows OS. It is a constraint enforced by operating system, there is nothing that you can do in Java to circumvent it. `"/"` means traversing to the child directory, and you cannot have it in dir name. – Pat Jul 21 '14 at 09:42
  • Windows -.-* This just happens when you develop under Linux and then try it under Windows :D Thx, that was the solution – Garog Jul 21 '14 at 09:43
  • While the linked question asks about Python, the answer is the same. You can't do it. – Stephen C Jul 21 '14 at 09:47
  • Exactly. That's why using "File.separator" in your Java code is always a good idea. It is your JVM that will put "/" under Unix-based OS or "\" under Windows. – DenisFLASH Jul 21 '14 at 09:47
  • @Iralution - Read the document again. It says 1) "/" is special, and 2) it is *silently* converted to a "\". Of course, you could use a Unicode *homoglyph* for "/" ... if one existed ... but then that is not a real forward-slash character at all. – Stephen C Jul 21 '14 at 09:49
  • @Iralution - a homoglyph for forward-slash does exist - 0x2044 – Stephen C Jul 21 '14 at 09:53
  • Yeah correct, it's the divison character. Anyway, I would not recommend to use it. – Iralution Jul 21 '14 at 10:16

0 Answers0