本文介绍了如何从SD卡读取TX文件中的txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我尝试使用arduino + ethernet来读取SD卡中的文件。 我有login.txt内容: 41001662 41001536 41001324 ..... 我可以读取所有文件,但我想逐行阅读。 txt 如何读取41001662到data1,41001365到data2?逐行阅读? 这是我的代码。我该怎么办呢? ///////////////////Hi, I try to read file from SD card using arduino + ethernet shiled.I have login.txt with content:410016624100153641001324.....I can read all file, but I want to read line by line of login.txtHow can I read 41001662 to data1, 41001365 to data2? read line by line?Here is my code. How can I fix it?///////////////////#include <SD.h>File myFile;void setup(){ Serial.begin(9600); Serial.print("Initializing SD card..."); pinMode(10,OUTPUT); if(!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); myFile = SD.open("login.txt"); if(myFile) { Serial.println("login.txt: "); while(myFile.available()) { Serial.write(myFile.read()); } myFile.close(); } else { Serial.println("error opening test.txt"); }}void loop(){}推荐答案 read() 从文件中读取一个字节。read()Read a byte from the file. 因此,为了逐行读取,您必须检测行尾字符(可能是,例如'\ n'')。请注意,您可以在Arduino端或PC上执行此操作。Hence, in order to read line by line you have to detect the end-of-line character (could be, for instance '\n'). Note you can do that either on Arduino side or on the PC one. 这篇关于如何从SD卡读取TX文件中的txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 18:56