javascript - Appending to the beginning of a text file and then saving as .js for iOS -
I want to open a txt file and add new one Let's line the text in the beginning of the file. I then want to save the file. JS file was. I've written some code but instead of overwriting the original text, adding a new line, I do not even know how to save the file as a .js file. Do I need to change?
Code 2014-07-25 15: 33: 00.631 App 1.0 [4125: ABC] Test EFGHIJclMnOPQRTUVX I'm telling you that maybe a little expensive but this is the best thing I can think of. I will do this It will print: Test yourself and work. Hope it helps. PS I will do this for the second part of your question: For getting the file path that you want to type, add extension .js And then do something like this: Hope it helps
NSString * content = @ "test"; NSString * filepath = [[NSBundle main bundle] pathForResource: @ "main" ofType: @ "txt"]; NSFileHandle * fileHandle = [NSFileHandle File HandleForWritingAtPath: filepath]; If (fileHandle) {// [fileHandle seekToEndOfFile]; [FileHandle writeData: [Content DataUsingEncoding: NSUTF8StringEncoding]]; [Filehandle closefile]; } And {[written content: path to file: encoding: NSStringEncodingConversionAllowLossy error: zero]; } NSArray * data = [[NSString stringWithContentsOfFile: file path encoding: 4 error: zero] Separate components from components: [NSCharacterSet newlineCharacterSet]]; NSLog (@ "% @", [Data ObjectExtends: 0]); Log
NSString * path = [[NSBundle mainBundle] pathForResource: @ "text" type: @ "txt"]; NSFileHandle * filehandle = [NSFileHandle fileHandleForWritingAtPath: Path]; NSString * towrite = @ "test"; // Get real content NSData * Origin = [NSMutableData dataWithContentsOfFile: Path]; // Create a temporary data frequency that you want to complete on the top NSMutableData * starts with the string * full = [[write encoding to use data: NSUTF8StringEncoding] mutableCopy]; // You add the original [full appendData: original]; // Write more data as you already know how [filehandle writeData: complete]; NSArray * Data = [[NSString stringWithContentsOfFile: path encoding: NSUTF8 string encoding error: zero] Separate agents from components set: [NSCharacterSet newlineCharacterSet]]; NSLog (@ "% @", [Data ObjectExtends: 0]);
testABCDEFGHIJKLMNOPQRSTUVWXYZ
[Full instrument file: pathToFileWithJSExtension];
Comments
Post a Comment