javascript - Appending to the beginning of a text file and then saving as .js for iOS -


Introduction

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

  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   

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

  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]);   

It will print:

  testABCDEFGHIJKLMNOPQRSTUVWXYZ   

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:

  [Full instrument file: pathToFileWithJSExtension];   

Hope it helps

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -