glib :File Utilities 读取文件内容

  gboolean g_file_get_contents (const gchar *filename, gchar **contents, gsize *length,GError **error); 

  如果filename含utf8格式,参考g_filename_to_utf8用法



1 gchar * txt, *ph0="D:\\电子书\\test\\LICENSE.txt";
2
3 //如果路径中含utf8则必须如下处理, 如果全英文路径可以跳过
4 gchar* ph01 =g_locale_to_utf8( ph0 ,-1, NULL, NULL ,NULL);
5
6
7 //此处为逆还原,备注
8 /*
9
10 gchar* ph02 =g_locale_from_utf8( ph01 ,-1, NULL, NULL ,NULL);
11 printf( ph02 );
12 */
13
14 g_file_get_contents(ph01,&txt,NULL,NULL);
15 printf( txt );
16 g_free(txt);
17 return 0;