//
// main.m
// cmdTry
//
// Created by Calos Chen on 2017/8/21.
// Copyright © 2017年 Calos Chen. All rights reserved.
// #import <Foundation/Foundation.h>
#import "class4.m"
#import "NSObject_class5.h" @class Fraction;
@interface Fraction : NSObject
{
int numberator;
int denominator;
NSString* name;
@public
double price;
Fraction *myf; }
@property double price;
-(void) print;
-(void) setNumberator: (int)n;
-(void) setName: (NSString*)na;
-(void) setInfo: (int) id name:(NSString*)name; @end @implementation Fraction @synthesize price; -(void) print
{
name= [name getBy:23 andName:@"Ok"];//
NSLog(@"%i it is %@",numberator,name);
}
-(void) setNumberator:(int)n
{
price=5;
numberator=n;
}
-(void)setName:(NSString *)na{
name=na;
} -(void) setInfo:(int)id name:(NSString *)na{
id=id;
name=na;
} @end //---- program section ---- int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
NSLog(@"who are you!");
}
NSNumber *xdd;
xdd=[NSNumber numberWithInt:45]; NSLog(@"why is it");
Fraction *myf= [[Fraction alloc] init];
[myf setName:@"calos"];
[myf print];
double price=myf->price; int a1=5;
float a2=3.23;
double a3=3.44;
char a4='c';
int a5=(int)a2;
for (int b=1; b<10;b++ ) {
a5+=b;
}
myf.price=88;
double b1=myf.price;
BOOL isPrime=NO;
NSLog(@"%i %f %e %c %i %c %g %e",a1,a2,a3,a4,a5,isPrime,b1,price);
NSLog(@"end........"); //file write
NSFileManager* fm=[NSFileManager defaultManager];
NSString* fname=@"a.txt";
NSFileHandle* fh=[NSFileHandle new];
NSData* data=nil;
NSCoder* coder=[NSCoder new];
[fm createFileAtPath:fname contents:nil attributes:nil];
if([fm isReadableFileAtPath:fname]){
[fh writeData:data];
}
else{
[[fh initWithCoder:coder] writeData:data];
} // 初始化管理类
NSFileManager * manager = [NSFileManager
defaultManager]; // 路径
NSString * DirectoryPath = [NSHomeDirectory()
stringByAppendingPathComponent:@"/desktop/我的文件夹1/我的文件夹2"]; NSError * error =
nil;
if ([manager
createDirectoryAtPath:DirectoryPath
withIntermediateDirectories:NO
attributes:nil
error:&error] !=
YES) {
// NSString * str = [error localizedDescription];
NSLog(@"创建失败");
}else {
// NSString * str = [error localizedDescription];
NSLog(@"创建成功");
} //file handle NSFileHandle *inFile, *outFile;
NSData *buffer;
NSData* d1=[@"sss" dataUsingEncoding:NSUTF8StringEncoding];
[[NSFileManager defaultManager] createFileAtPath:@"test.txt" contents:d1 attributes:nil]; //打开testfile.txt文件用于读取操作
inFile = [NSFileHandle fileHandleForReadingAtPath:@"testfile.txt"]; if(inFile == nil)
{
NSLog(@"Open of testfile.txt for reading failed!");
return 1;
} //创建一个文件用于写数据(第一次是必要的)
[[NSFileManager defaultManager] createFileAtPath:@"testout.txt" contents:nil attributes:nil] ; //打开testout.txt文件用于写入操作
outFile = [NSFileHandle fileHandleForWritingAtPath:@"testout.txt"]; if(outFile == nil)
{
NSLog(@"Open of testout.txt for writing failed!");
return 2;
} //
[outFile truncateFileAtOffset:0]; //从inFile中读取数据,并将其写入到outFile中
buffer = [inFile readDataToEndOfFile]; [outFile writeData:buffer]; //关闭两个文件
[inFile closeFile];
[outFile closeFile]; return 0;
} //for today: 2017-08-21, I have read and practiced the first 153 pages of the object-c 2.0, now, I have known object-c classes and data types, and how to announce and implement the classes and class members, as well as functions in the class implementation. also property synthesize methods. loops.
//homework: implement a new class, and new interface and fill the class with members and all tangible members, then use all of them. @class declaration. So, write a console program with object-c.

目前可以使用 Object-c 的 file 处理, 可以操作目录,并读写文件, 控制台程序生成了正常的文件,感觉比较欣慰,文件处理也算蛮大的一步了,知道了一些 oc 常用的库处理,在渐渐地变熟练

[object-c 2.0 程序设计]object-c file handle (二)的更多相关文章

  1. document.forms[0].submit object is not a function

    今天在做项目的时候发现了一个问题:document.forms[0].submit object is not a function. 这个问题是在用JavaScript 代码来提交一个表单时发生的. ...

  2. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'

    报错: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlace ...

  3. * -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]’

    错误描述: * -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object fr ...

  4. 原型相关的方法isPrototypeOf、Object.getPrototypeOf、hasOwnProperty、Object.getOwnPropertyName、Object.keys

    在看<高程3>第六章的<面向对象的程序设计>的原型那一节时,有一下5个函数,功能较为接近,但是又都很基础,很重要 所以在此,加以说明,以便日后复习 function Perso ...

  5. Android学习笔记_46_Android的intent之间Object、List、List<Object>和全局变量数据的传递(Parcelable Serializable)

    转http://blog.csdn.net/pku_android/article/details/7456305 一.传递List<String>和List<Integer> ...

  6. List<List<Object>> list = new ArrayList<List<Object>>(); 求回答补充问题 list.get(position).add(Object);为什么会报错啊我想在对应的list里面添加对象

    public static void main(String[] args){ List<List<Object>> list = new ArrayList<List& ...

  7. PHP json_decode object时报错Cannot use object of type stdClass as array

    PHP json_decode object时报错Cannot use object of type stdClass as array php再调用json_decode从字符串对象生成json对象 ...

  8. 自己写的demo。List<HashMap<String,Object>>=new ArrayList<HashMap<String,Object>>

    package com.pb.collection; import java.util.ArrayList; import java.util.HashMap; import java.util.It ...

  9. 关于 warning CS0659:“***”重写Object.Equals(object o)但不重写Object.GetHashCode()

    对象相等性和同一性 System.Object 类型提供了以下方法, namespace System { // // 摘要: // 支持 .NET Framework 类层次结构中的所有类,并为派生 ...

随机推荐

  1. Java的框架是什么意思

    框架就是一些类和接口的集合,通过这些类和接口协调来完成一系列的程序实现. JAVA框架可以分为三层:表示层,业务层和物理层.框架又叫做开发中的半成品,它不能提供整个WEB应用程序的所有东西,但是有了框 ...

  2. 『AngularJS』Service

    理解Angular 服务 什么是Angular Service Angular 服务是为web应用执行特定任务的单例对象或方法. 注:如果组件是为了内容呈现的功能复用,那么服务就是为组件进行功能复用. ...

  3. 「日常训练」「小专题·USACO」 Wormholes(1-4)

    题意 之后补充. 分析 这是一条很好的考察递归(或者说搜索)的题目.它的两个过程(建立初步解,验证)都用到了递归(或者说运用递归可以相当程度的减少代码量). 具体实现见代码.注意,为了使用std::p ...

  4. C++学习012友元

    何为友元,我的理解,友元就是把另一个类当作是我的朋友,朋友之间,是可以访问一些私有的变量的. 所以,当我们将一个累声明为自己的友元类的时候,那么这个类就可以访问我们自己类中的某些私有变量等 当我把某个 ...

  5. 【转】 The user specified as a definer ('root'@'') does not exist when using LOCK TALBE

    在linux下,用mysql的导出语句: mysqldump -u root -pPasswd table >/home/lsf/test.sql 出现了 Got error: 1449: Th ...

  6. Hadoop Yarn on Docker

    搭建Hadoop Yarn on Docker 一.概览 Docker基于Linux Container技术整合了一堆易用的接口用于构建非常轻量级的虚拟机.Docker Container Execu ...

  7. hdu 2838 Cow Sorting (树状数组)

    Cow Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. C#范型实例化对象

    T s = System.Activator.CreateInstance<T>();

  9. BZOJ1044 [HAOI2008]木棍分割 【二分+Dp】

    1044: [HAOI2008]木棍分割 Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 4281  Solved: 1644 [Submit][St ...

  10. 工具——SVN常用命令

    SVN一般都是团队合作做一个项目所需用到的,为了是版本的统一 ;1. Check out——从服务器端取得代码    把服务器资料库里存放的某个项目代码取出来,放到本地主机中,这个动作叫做“check ...