import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.TextView;
/**
* This activity shows how to write and read data from sdcard
* @author FaYnaSoft Labs
*
*/
public class Main extends Activity {
private static final String APP_TAG = "tag";
private TextView readOutput;
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
this.setContentView(R.layout.main);
readOutput = (TextView) findViewById(R.id.output);
String fileName = "test-" + System.currentTimeMillis() + ".txt";
// create /sdcard/test_folder
File sdDir = new File(Environment.getExternalStorageDirectory().getPath());
if (sdDir.exists() && sdDir.canWrite()) {
File testDir = new File(sdDir.getAbsolutePath() + "/test_folder");
testDir.mkdir();
if (testDir.exists() && testDir.canWrite()) {
File file = new File(testDir.getAbsolutePath() + "/" + fileName);
try {
file.createNewFile();
} catch (IOException e) {
Log.e(APP_TAG, "error creating file", e);
}
if (file.exists() && file.canWrite()) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
fos.write("Hello, World!".getBytes());
} catch (FileNotFoundException e) {
Log.e(APP_TAG, "ERROR", e);
} catch (IOException e) {
Log.e(APP_TAG, "ERROR", e);
} finally {
if (fos != null) {
try {
fos.flush();
fos.close();
} catch (IOException e) {
}
}
}
} else {
Log.e(APP_TAG, "error writing to file");
}
} else {
Log.e(APP_TAG, "ERROR, unable to write to /sdcard/test_folder");
}
} else {
Log.e(APP_TAG, "ERROR, /sdcard path not available");
}
// Read file block
File readFile = new File(sdDir.getPath() + "/test_folder/" + fileName);
if (readFile.exists() && readFile.canRead()) {
FileInputStream fis = null;
try {
fis = new FileInputStream(readFile);
byte[] reader = new byte[fis.available()];
while (fis.read(reader) != -1) {
}
readOutput.setText(new String(reader));
} catch (IOException e) {
Log.e(APP_TAG, e.getMessage(), e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
}
}
}
} else {
readOutput.setText("Unable to read/write sdcard file, see logcat output");
}
}
}
Mac 快捷键列表
转到(Go To)
Control-F2
到菜单
Control-F3
到Dock
切换(Switch)
Command-Tab
在程序间切换
Command-`
在程序中的窗口间切换
窗口(Window)
Command-H
隐藏
Command-M
最小化
Command-N
新建
Command-O
打开
Command-P
打印
Command-Q
退出
Command-Q
退出
Command-W
关闭
F9
显示所有程序打开的窗口
F10
显示当前打开的窗口
F11
隐藏所有窗口并显示桌面
文件(File)
Command-S
保存
Command-Shift-S
另存为
Command-Shift-N
新建文件夹
Command-I
简介
Command-Option-I
显示多个项目的简介
移动(Move)
Home
移动到文件开头
End
移动到文件结尾
Command-←
移动到行首
Command-→
移动到行尾
Option-←
向左移动一个单词
Option-←
向右移动一个单词
选择(Select)
Shift-Home
选择到文件开头
Shift-End
选择到文件结尾
Shift-Command-←
选择到行首
Shift-Command-→
选择到行尾
Shift-Option-←
向左选择一个单词
Shift-Option-←
向右选择一个单词
编辑(Edit)
Fn-Backspace
删除光标后的字符
Finder
Space
Quick Look
Command-Delete
删除
Command-Delete-Shift
清空垃圾桶
Command-Shift-A
转到应用程序目录
Command-Shift-C
转到COMPUTER目录
Command-Shift-H
转到HOME目录
Command-Shift-B
通过蓝牙传送文件
屏幕(Screen)
Control-Shift-Eject
屏幕休眠
Command-Shift-3
截取整个屏幕
Command-Shift-4
截取指定区域
Command-Option–
缩小
Command-Option-=
放大
Command-Option-Control-8
将屏幕从“白底黑字” 切换成 “黑底白字”
Command-Option-Ctrl->
提高对比度
Command-Option-Ctrl-<
降低对比度
系统(System)
Command-Option-Escape
强制退出程序
Command-Option-Eject
睡眠
Command-Control-Eject
关闭所有程序并重新启动
Command-Space
切换语言
Command-esc
Front Row
Command-?
获得帮助
Command-F5
打开/关闭VoiceOver(朗读菜单、按钮等)
音量(Volume)
Shift-volume
调整音量但不发出提示音
Option-volume
打开“声音”的“系统预置”
Shift-Option-volume
微调音量(原有的16格调节细化为64格)
其它(Others)
Command-Shift-Y
用当前选中的文字生成便签
我不喜欢在博客里回答问题,我只是希望博客干净一点,除非你做的效果和更好的方法可以跟帖
如果你要问我问题或者和我交流 请加我qq 3323297
谢谢 如果我能帮上 会帮你的,希望我们是朋友
也希望不要在跟帖了 谢谢,您也可以加入群 6884330,不过此群已满 请加入 75542406此群