C 按行讀取檔案(但是最後一行會多輸出一行)
#include <stdio.h>
int main()
{
char filename[] = "E:\\data_test\\commands.txt"; //檔名
FILE *fp;
char StrLine[1024]; //每行最大讀取的字元數
if((fp = fopen(filename,"r")) == NULL) //判斷檔案是否存在及可讀
{
printf("error!");
return -1;
}
while (!feof(fp))
{
fgets(StrLine,1024,fp); //讀取一行
printf("%s\n", StrLine); //輸出
}
fclose(fp); //關閉檔案
return 0;
}
相關推薦
C 按行讀取檔案(但是最後一行會多輸出一行)
#include <stdio.h> int main() { char filename[] = "E:\\data_test\\commands.txt"; //檔名 &nb
C/C++ 按行讀取檔案
本文程式碼都在Windows/VC++6.0下測試過, 在linux/g++下也沒有問題。 但是請一定注意linux和Windows檔案格式的區別,比如: &n
C語言之按行讀取檔案
原文字檔案 outlook,temperature,humidity,windy,play sunny,hot,high,FALSE,no sunny,hot,high,TRUE,no overcas
java按行讀取檔案並對檔案進行加密和解密
package com.alibaba.datax.plugin.reader.selfxmlfilereader.util; import java.io.UnsupportedEncodingException; import java.security
shell指令碼按行讀取檔案並解析
shell指令碼讀取一個配置檔案,配置檔案的格式如下: name=abc pwd=123456 permission=mop 檔名稱為 config.cfg 要在shell腳本里讀取這個配置檔案,並且把值一一賦給相應的變數,實現如下 while read l
shell指令碼-----按行讀取檔案
[email protected]:5.read-line$ cat file.bin hello world this is 1 this is 2 this is 3[email protected]:5.read-line$ ./read-line.sh file.bin ###
Java按行讀取檔案並輸出
public class ReadFileByLines { public static void main(String[] args) { try{ //1.開啟一個file
java 按行讀取檔案
package cn.com.yy.controller; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNot
CStdioFile按行讀取檔案.
virtual LPTSTR ReadString( LPTSTR lpsz, UINT nMax ); virtual BOOL ReadString( CString& rString ); CStdioFile aFile; CF
NIO按行讀取檔案內容,並打印出來
package com.broada.wssh.groovy; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuf
Java 實現按行讀取檔案並且將行中的重複資料刪除
package com.gaden.delerepeat; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStr
java按行讀取檔案實現方法一
public static void main(String[] args) throws IOException { FileInputStream inputStream = new FileInputStream("d://a.txt");
python按行讀取檔案 如何去掉換行符 "\n"
程式如下: for line in file.readlines(): line=line.strip('\n') 使用strip()函式去掉每行結束的\n strip()函式原型 宣告:s為字串,rm為要刪除的字元序列 s.strip(rm) 刪
java按行讀取檔案
File file = new File(srcPath); FileInputStream fileInputStream = new FileInputStream(file); InputStreamReader inputStreamReader = new Inpu
Java 按行讀取檔案按行寫入檔案並以空格分割字串
首先是按行讀取字串 import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public c
遞迴查詢檔案及其子檔案(需傳入一棵樹和id)
首先明確大致的思路: 1.已知的資料有整棵樹 和 要刪除資料的id 2.根據id能夠查到其在 樹中對應的List(需遍歷) 3.找到List後確定要刪除List的children(treeNode.getId()==id) 4.判斷找到的treeNode是否有chil
C++中string類及檔案流類(ofstream,ifstream)的基本操作---按行讀取文件
先說明一個問題:java構建物件只能使用new的方法,而C++則不然。 下面程式碼實現讀取test.txt檔案中的內容並顯示,同時將某一個字串輸入到檔案test1.txt中。 函式getline(ifstream& param1, string& param
C++如何按行讀取txt檔案並存儲到字串中?
今天老師留了一道C++作業。 //91. C++輸入和輸出:編寫一個程式,將下面的資訊表寫入檔案stock.txt中 //Shen fa zhan 000001 //Shang hai qi che 600104 //Guang ju neng
Java文字檔案的按行讀取
package my; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.InputStrea
java指定編碼的按行讀寫txt檔案(幾種讀寫方式的比較)
輸入輸出的幾種形式 1.FileReader,FileWriter File r = new File("temp.txt") FileReader f = new FileReader(name);//讀取檔案name BufferedReader b = new Buf