Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Read text file


  • Please log in to reply
6 replies to this topic

#1 Nissim

Nissim

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationNew Zealand

Posted 07 November 2011 - 06:38 AM

Hi there Can someone please show me an example how to read a text file? Many thanks

#2 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

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" :P
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# :P


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 d
own - 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 Nissim

Nissim

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationNew Zealand

Posted 07 November 2011 - 07:27 AM

Many thanks for your prompt reply Are you sure Stream is supported by Micro framework ? I cant get your example to work,, sorry

#4 Nissim

Nissim

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationNew Zealand

Posted 07 November 2011 - 08:17 AM

can you kindly show me the using directive ?

#5 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 07 November 2011 - 10:26 AM

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 (I hope it is this syntax in VB, in C# it is :P) PS: This is a very nice "Getting started" to work with streams. Nice explaination of what streams are and how to write/read to/from them :) MSDN: http://msdn.microsof...e/cc163710.aspx It's always good to have some background knowledge :) Greets, Markus

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 d
own - 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 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 07 November 2011 - 07:27 PM

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

Have you checked to see if the System.IO dll is in the references for the project?

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 Nissim

Nissim

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationNew Zealand

Posted 07 November 2011 - 09:01 PM

oh sorry, I forgot to add a reference to System I.O I thank you for your assistance




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.