[object-c 2.0 程序设计]object-c file handle (二)
//
// 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 (二)的更多相关文章
- document.forms[0].submit object is not a function
今天在做项目的时候发现了一个问题:document.forms[0].submit object is not a function. 这个问题是在用JavaScript 代码来提交一个表单时发生的. ...
- 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 ...
- * -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]’
错误描述: * -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object fr ...
- 原型相关的方法isPrototypeOf、Object.getPrototypeOf、hasOwnProperty、Object.getOwnPropertyName、Object.keys
在看<高程3>第六章的<面向对象的程序设计>的原型那一节时,有一下5个函数,功能较为接近,但是又都很基础,很重要 所以在此,加以说明,以便日后复习 function Perso ...
- Android学习笔记_46_Android的intent之间Object、List、List<Object>和全局变量数据的传递(Parcelable Serializable)
转http://blog.csdn.net/pku_android/article/details/7456305 一.传递List<String>和List<Integer> ...
- 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& ...
- 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对象 ...
- 自己写的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 ...
- 关于 warning CS0659:“***”重写Object.Equals(object o)但不重写Object.GetHashCode()
对象相等性和同一性 System.Object 类型提供了以下方法, namespace System { // // 摘要: // 支持 .NET Framework 类层次结构中的所有类,并为派生 ...
随机推荐
- Android应用开发中的夜间模式实现(一)
前言 在应用开发中会经常遇到要求实现夜间模式或者主题切换具体例子如下,我会先讲解第一种方法. 夜间模式 知乎 网易新闻 沪江开心词场 Pocket 主题切换 腾讯QQ 新浪微博 我今天主要是详述第一种 ...
- adb 命令模拟按键事件
转自:http://blog.csdn.net/jlminghui/article/details/39268419 例子:adb shell input keyevent 4 #这条命令相当于按了设 ...
- HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...
- lintcode-104-合并k个排序链表
104-合并k个排序链表 合并k个排序链表,并且返回合并后的排序链表.尝试分析和描述其复杂度. 样例 给出3个排序链表[2->4->null,null,-1->null],返回 -1 ...
- .Net 面试总结
今天去面试了一家公司,做电子商务类的网站的,公司的老板应该比较有能量,可以同时拿下若干项目,技术负责人给提了几个问题: 记不清顺序了 .net 构析函数的作用 泛型的主要作用及应用方面 结构与类的区别 ...
- Java中动态代理实现原理深究
一.前言 笔者平时开发使用“动态代理”不多,最近在看设计模式的时候,“动态代理”又在面前晃了几次,所以这次想从源码的角度去分析动态代理的实现原理,以窥探其精妙~ 二.正文 2.1 静态代理 本文源码 ...
- delphi中写SQL语句中变量的注意事项
1.procedure TForm1.btn1Click(Sender: TObject); var s: String; begin S := 'select * from TMarketI ...
- Java IO 之 FileFilter与FilenameFilter
FileFilter与FilenameFilter可以实现对文件的过滤,他们都是接口,具体的过滤规则需要我们自己编写 1.FileFilter package org.zln.io.file; imp ...
- div加了float后 四个特性
1.宽度变成0 2.左漂浮 或者右漂浮 3.后面的标签占据原来的位置 4对前面的div没有影响 他会浮动到前面div下面
- hdu 1853 Cyclic Tour (二分匹配KM最小权值 或 最小费用最大流)
Cyclic Tour Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others)Total ...