Crash: if the file name consists of a slash, for example, "te / st.pdf"

If the file name consists of a slash, for example, "te / st.pdf"

[data writeToFile:@"/Documents/te/st.pdf" atomically:YES encoding:NSUTF8StringEncoding error:nil]

is there any solution instead of replacing the slash '/' with another character.

+4
source share
3 answers

For some odd reason, you should use. \:So, it will be

[data writeToFile:@"/Documents/te\:st.pdf" atomically:YES encoding:NSUTF8StringEncoding error:nil]

It works, but the compiler complains about an unknown escape sequence. If you run ls -lain the folder where you create the slash file, you will see that it is calledthe:st.pdf

+2
source

, , macos. , , , , .

 NSError * err = NULL;
 BOOL result = [[NSFileManger     
 defaultManger moveItemAtPath:@"/  
    Documents/te/st.pdf" toPath: @"/
  Documents/test.pdf"   error:&err];
 if(!result)
NSLog(@"Error: %@", err);
0

: :

\:. , XCode 6.3.2 . . :

[data writeToFile:@"/Documents/te:st.pdf" atomically:YES encoding:NSUTF8StringEncoding error:nil]

: (), , Unicode = > ( U + A789)

0

All Articles