如何从一个文件中读取并写入另一个文件? [英] How do I read from one file and write to another ?

查看:79
本文介绍了如何从一个文件中读取并写入另一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我对文件处理不是很有经验,所以我是

请求一点帮助。


我有一个名为geotext_1a.csv

的文件,它是一个csv文件,如下所示:


" 2.6.190.56,2.6.190.63,33996344,33996351,G B,英国

" 3.0.0.0" ," 4.17.135.31"," 50331648"," 68257567"," US" ,美国

4.17.135.32,4.17.135.63,68257568,68257599,CA,加拿大



我想从中获取一些数据,并写一个名为geo_01.txt的文件


,看起来像这样: br />

33996344,33996351,United Kingdom

50331648,68257567,United States

68257568,68257599,Canada



现在我已经编写了一些代码,但我使用

文件函数将内容放入数组中。


由于文件大几兆字节,这导致内存

故障问题。


这就是我所拥有的:

展开 | 选择 | Wrap | 行号

解决方案

代码执行的哪个阶段是您的内存问题?


实际上,当我运行它时,它似乎正在工作,直到它到达

行并且发生这个致命错误:


致命错误:第9行/home/ew78gt/public_html/sys/convert.php中允许的内存大小为16777216字节(试图分配13个字节)


试试这个:

展开 | 选择 | Wrap | 行号

Hello,

I am not very experienced with file handling, so I am
asking for a little help with this.

I have a file called "geotext_1a.csv"
and it is a csv file looking like this:

"2.6.190.56","2.6.190.63","33996344","33996351","G B","United Kingdom"
"3.0.0.0","4.17.135.31","50331648","68257567","US" ,"United States"
"4.17.135.32","4.17.135.63","68257568","68257599", "CA","Canada"


I want to take some data from it and write a file called geo_01.txt

and will look like this :

33996344,33996351,United Kingdom
50331648,68257567,United States
68257568,68257599,Canada


Now I have written some code but I used
the file function to put the contents into an array.

As the file is a few megabytes big, this has caused memory
failure problems.

This is what I have:

Expand|Select|Wrap|Line Numbers

解决方案

Which stage of the code execution is your memory problem occurring at?


Actually, when I run this , its seems to be working until it gets to a
line and this fatal error occurs:

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 13 bytes) in /home/ew78gt/public_html/sys/convert.php on line 9


Try this:

Expand|Select|Wrap|Line Numbers


这篇关于如何从一个文件中读取并写入另一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆