魏哲的空间 blog.weizhe.net

魏哲的空间

站名: 魏哲的空间

网址: http://blog.weizhe.net

目录: 电脑网络 > 手机通信

PR:

Alexa: 4,481,036

备案号:

服务器IP: 104.160.42.147   北美地区

描述: 关心linux python golang

查询: [ 网站综合查询 | PR查询 | Alexa排名 | 同IP网站 ]

详细介绍

搜索:魏哲的空间关心linux python golangFeed Rss首页Golang 笔记快乐六一七月 18th, 2015Debian快捷搭建SAMBA服务No Comments, python, by 魏 哲, 662 views.# rm /etc/samba/smb.conf /etc/samba/smb.conf.bak# emacs /etc/samba/smb.conflog file = /var/log/samba/log.%m[movie]comment = Moviepath = /pathto/Movieread only = yespublic = yes# /etc/init.d/samba restart七月 16th, 2015轻松搭建基于go1.5开发Android应用的环境4 Comments, android, golang, linux, by 魏 哲, 5,487 views.第一步. 部署go1.5beta2export PATH=$PATH:$GOPATH/bin第二步 部署golang/mobile$ go get golang.org/x/mobile/cmd/gomobile$ gomobile init -v如果提示没有权限如下runtimego install runtime: mkdir /usr/local/go/pkg/android_arm/: permission deniedgomobile: go install std for android/arm failed: exit status 1Downloading https://dl.google.com/go/mobile/gomobile-ndk-r10e-linux-x86_64.tar.gz.Downloading https://dl.google.com/go/mobile/gomobile-openal-soft-1.16.0.1.tar.gz.Building standard library for android/arm.runtimeerrorssync/atomic...testing/quicknet/rpc/jsonrpcDone, build took 23s.第三步 使用go run 在桌面测试程序$ go run main.go第四步 使用gomobile直接生成apk格式Android应用.$ gomobile build
$ ls
main.go basic.apk
$ gomobile install
最后安装到Android L
五月 24th, 2015
golang 文件操作
No Comments, golang, by 魏 哲, 705 views.
包含以下的这些函数
func NewFile(fd uintptr, name string) *File
func Open(name string) (file *File, err error) 以只读方式打开一个存在的文件,打开就可以读取了。
func OpenFile(name string, flag int, perm FileMode) (file *File, err error)
flag可选值(掩码):
O_RDONLY int = syscall.O_RDONLY // 只读
O_WRONLY int = syscall.O_WRONLY // 只写
O_RDWR   int = syscall.O_RDWR   // 读写
O_APPEND int = syscall.O_APPEND // 在文件末尾追加,打开后cursor在文件结尾位置
O_CREATE int = syscall.O_CREAT  // 如果不存在则创建
O_EXCL   int = syscall.O_EXCL   //与O_CREATE一起用,构成一个新建文件的功能,它要求文件必须不存在
O_SYNC   int = syscall.O_SYNC   // 同步方式打开,没有缓存,这样写入内容直接写入硬盘,系统掉电文件内容有一定保证
O_TRUNC  int = syscall.O_TRUNC  // 打开并清空文件
func (f *File) Chdir() error              改变当前的工作目录
func (f *File) Chmod(mode FileMode) error  改变权限
func (f *File) Chown(uid, gid int) error    改变所有者
func (f *File) Close() error                 关闭文件
func (f *File) Fd() uintptr            返回文件句柄
func (f *File) Name() string           返回文件名
func (f *File) Read(b []byte) (n int, err error) 读取文件
func (f *File) ReadAt(b []byte, off int64) (n int, err error) 从off开始读取文件
func (f *File) Readdir(n int) (fi []FileInfo, err error)   读取文件目录返回n个fileinfo
func (f *File) Readdirnames(n int) (names []string, err error) 读取文件目录返回n个文件名
func (f *File) Seek(offset int64, whence int) (ret int64, err error) 设置读写文件的偏移量,whence为0表示相对于文件的开始处,1表示相对于当前的位置,2表示相对于文件结尾。他返回偏移量。如果有错误返回错误
func (f *File) Stat() (fi FileInfo, err error) 返回当前文件fileinfo结构体
func (f *File) Sync() (err error)  把当前内容持久化,一般就是马上写入到磁盘
func (f *File) Truncate(size int64) error   改变当前文件的大小,他不改变当前文件读写的偏移量
func (f *File) Write(b []byte) (n int, err error) 写入内容
func (f *File) WriteAt(b []byte, off int64) (n int, err error) 在offset位置写入内容
func (f *File) WriteString(s string) (ret int, err error) 写入字符
import (
"fmt"
"io/ioutil&quo

猜你喜欢