0
파일에서 읽으려고 NSInputstream을 사용했습니다. 읽은 후 NSInputstream 내용물 empty.I가.txt 파일을 NSInputstream으로 읽음 filestream에 사용할 수있는 바이트가 없습니다.
- (void)startSend
{ AppDelegate에 * mainDelegate = (AppDelegate에 *) [UIApplication sharedApplication] 대리자 (서버 FTP로 .txt 파일을 전송하기위한) 코드가 사용된다
BOOL success;
NSURL * url;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *testsessionid=[defaults stringForKey:@"testsessionid"];
NSString *writeFileName=[NSString stringWithFormat:@"%@%@.txt",testsessionid,mainDelegate.studentID];
NSLog(@"Write file name %@",writeFileName);
NSArray *searchPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentFolderPath = [searchPaths objectAtIndex: 0];
NSString *filePath= [documentFolderPath stringByAppendingPathComponent: writeFileName];
NSLog(@"Write folder name %@",filePath);
[email protected]"/Users/sree/Desktop/ARATHY/BCLSTestApp/BCLSTest/Question2.txt";
assert(filePath != nil);
assert([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
assert([filePath.pathExtension isEqual:@"txt"] );
assert(self.networkStream == nil); // don't tap send twice in a row!
assert(self.fileStream == nil);
// First get and check the URL.
url = [NSURL URLWithString:@"ftp://[email protected]/bclstest/243"];
success = (url != nil);
if (success) {
// Add the last part of the file name to the end of the URL to form the final
// URL that we're going to put to.
url = CFBridgingRelease(
CFURLCreateCopyAppendingPathComponent(NULL, (CFURLRef) url, (CFStringRef) [filePath lastPathComponent], false)
);
success = (url != nil);
}
// If the URL is bogus, let the user know. Otherwise kick off the connection
if (! success) {
NSLog(@"Invalid URL");
} else {
// Open a stream for the file we're going to send. We do not open this stream;
// NSURLConnection will do it for us.
self.fileStream = [NSInputStream inputStreamWithFileAtPath:filePath];
// self.fileStream=[[NSInputStream alloc] initWithFileAtPath:filePath];
if(self.fileStream==nil)
NSLog(@"FILE DOESN'T EXIST");
else
NSLog(@"FILE EXISTS");
assert(self.fileStream != nil);
BOOL hasbyte=[self.fileStream hasBytesAvailable];
if (hasbyte==YES)
NSLog(@"Has contents");
else
NSLog(@"no contents");
[self.fileStream open];
// NSLog(@"SIZE OF STREAM IS >> %d",fi);
// Open a CFFTPStream for the URL.
self.networkStream = CFBridgingRelease(
CFWriteStreamCreateWithFTPURL(NULL, (CFURLRef) url)
);
assert(self.networkStream != nil);
success = [self.networkStream setProperty:@"edugame" forKey:(id)kCFStreamPropertyFTPUserName];
assert(success);
success = [self.networkStream setProperty:@"[email protected]" forKey:(id)kCFStreamPropertyFTPPassword];
assert(success);
self.networkStream.delegate = self;
[self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.networkStream open];
// Tell the UI we're sending.
//[self sendDidStart];
}
} 그것은 인쇄
는 를 "파일이 존재하지 않습니다"그러나 다음 줄에 "아무 내용"
파일이 비어 있지 않습니다.