php读取文件内容:
- //**************第一种读取方式*****************************
- header("content-type:text/html;charset=utf-8");
- //文件路径
- $file_path="text.txt";
- //判断是否有这个文件
- if(file_exists($file_path)){
- if($fp=fopen($file_path,"a+")){
- //读取文件
- $conn=fread($fp,filesize($file_path));
- //替换字符串
- $conn=str_replace("\r\n","
",$conn); - echo $conn."
"; - }else{
- echo "文件打不开";
- }
- }else{
- echo "没有这个文件";
- }
- fclose($fp);
- //*******************第二种读取方式***************************
- header("content-type:text/html;charset=utf-8");
- //文件路径
- $file_path="text.txt";
- $conn=file_get_contents($file_path);
- $conn=str_replace("\r\n","
",file_get_contents($file_path)); - echo $conn;
- fclose($fp);
- //******************第三种读取方式,循环读取*****************
- header("content-type:text/html;charset=utf-8");
- //文件路径
- $file_path="text.txt";
- //判断文件是否存在
- if(file_exists($file_path)){
- //判断文件是否能打开
- if($fp=fopen($file_path,"a+")){
- $buffer=1024;
- //边读边判断是否到了文件末尾
- $str="";
- while(!feof($fp)){
- $str.=fread($fp,$buffer);
- }
- }else{
- echo "文件不能打开";
- }
- }else{
- echo "没有这个文件";
- }
- //替换字符
- $str=str_replace("\r\n","
",$str); - echo $str;
- fclose($fp);
- 读取INI配置文件的函数:
- $arr=parse_ini_file("config.ini");
- //返回的是数组
- echo $arr['host']."
"; - echo $arr['username']."
"; - echo $arr['password']."
";
参考链接:
php读取文件内容至字符串并加以处理的代码
学习php读取文件内容的方法
Android 提供了三种数据存储方式,第一种是文件存储;第二种是SharedPreferences存储;第三种就是数据库SQLiteDatabase存储。文件存储我就不用多说了,而SharedPreferences可以存取简单的数据(int,double,float.etc),它经常用于数据缓存,因为它读取存储简单。详细可以参见本系列。Android高手进阶教程(七)之----Android 中Preferences的使用! 今天我们将讲一下SQLiteDatabase的使用。而掌握SqliteData










