Read text file
#1
Posted 07 November 2011 - 06:38 AM
#2
Posted 07 November 2011 - 07:13 AM
Hi there
Can someone please show me an example how to read a text file?
Many thanks
Dim stream as New FileStream("file.doc", FileMode.Create, FileAccess.Write)
Dim writer as new StreamWriter(stream)
writer.WriteLine("This is an example of using files")
writer.Flush()
writer.Close()
Explanation line for line:
1. Create a filestream. Streams are usally used to read and write data (e.g. NetworkStreams etc.)
2. On to of a stream, you need something to handle the data in the stream. For that you use an StreamWriter (Write) or an StreamReader (Read)
3. Use the StreamWrite to write a line
4. Flush() is used to ensure that the data is really written to file. WriteLine only says "Write to file when it fits you good" (very simplified sayed)... Flush says "Write NOW"
5. Close writer (as I know the stream gets closed automaticly if writer is closed) to free ressources
Hope i could help, I just use C#
EDIT: Oops, you wanted to read the file... Then use the following:
Dim stream as New FileStream("file.doc", FileMode.Open, FileAccess.Read)
Dim reader as new StreamReader(stream)
Dim readString as String
readString = fileReader.ReadLine() //returns the first line and sets the cursor to the next line
NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and down - and upload files
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#3
Posted 07 November 2011 - 07:27 AM
#4
Posted 07 November 2011 - 08:17 AM
#5
Posted 07 November 2011 - 10:26 AM
NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and down - and upload files
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#6
Posted 07 November 2011 - 07:27 PM
Have you checked to see if the System.IO dll is in the references for the project?Normally, it is System.IO, I think it's the same on the MicroFramework...
I already worked with it, so I'm sure it is supported.
Use:
using System.IO
Regards,
Mark
To be or not to be = 0xFF
Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life
Follow @nevynuk on Twitter
#7
Posted 07 November 2011 - 09:01 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users