Read file to variable in Visual Basic - vb.net

I want to be able to put a file to a variable so I can interact with it. For example I could put a wav file into a variable and play it back without having to distribute the separate file. Is this possible for instance by using Base64. I have seen some Python programs for example that have images embedded in the code.

Yes, you could conceivably store the contents of a binary .wav file as a static, uuencoded text array.
Probably a better way to go about it would be to create a "resource" for your binary data:
http://msdn.microsoft.com/en-us/library/xbx3z216.aspx

Related

How to read/edit Parasoft SOATEST .tst file by code or manually?

I need to read the .txt file as raw text or by code to extract the data keyed in the test suite (resource/assertors,....). Is there any way to do that? by code or any editor.
If you have binary format of tst file then there could be a problem, there is no official API to read it.
It's very old format, I don't think that is still in use.
There could be also two, newest, formats of tst:
compressed XML
XML
In case of compressed XML you have to unzip it and then you have access to XML, where you can read it as text file.
In case of XML, it's just XML, you can read it as pure text file.
There is no official API which allows to read it in similar way as SOAtest's GUI to use in code i.e.: in Java.

How to compare and find the differences between two XML files in cocoa?

This is a bit of a two part question, for working with 40mb xml files.
• What’s a reasonable size to store in memory for a program running continually in the background?
• How to find what has changed in an XML file.
So on the first read the XML is loaded into NSData, then uploaded to the server.
Now instead of uploading a 40mb XML every time it changes, I would prefer to upload a “delta” file containing only what has changed. The program would monitor the file for change, and activate when it’s been modified. From what I can see, I would need to parse an old version of the xml file and parse the modified xml file, then compare them? Is it unreasonable to store 80mb in memory like this every time the file is modified?. Now I’m assuming that this has to be done with a DOM parser because I can’t see how you could compare two files like that with a SAX parser since it only has part of the file stored?
I'm a newbie at this so any help would be appreciated!
To compare two files:
There are many ways to do, (As file is to be considered, I may not be correct):
sdiff file1.xml file2.xml A unix command
You can use this command with apple script.
-[NSFileManager contentsEqualAtPath:andPath:]
This method checks to see if two files at given path are the same file, then compares their size, and finally compares their contents.
For other part:
What size is considered for background process, I dont think so, for an application it matters. You can save these into temporary files. Even safari uses 130+ MB as you can easily check through Activity monitor.
NSXMLParser ended up being the most useful for this

How do I create a custom file format on mac?

I want to create a file type that contains objective c code and image data. But I want it not readable by a text editor. How best do I do this?
Assuming you already know how to append the code and the image in a file (which, however, should be a pretty easy task), you just need to crypt the data before storing. You can easily do it using, i.e., AES encryption.

What is the best way of reading/writing binary input/output files with MapReduce?

In all samples I've seen so far, mapreduce apps take text files as input and write text as output.
I'd like my app to read objects from the binary file and write objects back to output file.
What is the best way to do that in MapReduce?
I'm writing the app in java
SequenceFile provides a persistent data structure for binary key-value pairs. You can find more information in the below URL.
http://wiki.apache.org/hadoop/SequenceFile
http://hadoop.apache.org/common/docs/current/api/org/apache/hadoop/io/SequenceFile.html

opening and writing to files in visual basic 2010

Am writing a simple application which can write a to pdf,doc,xls and access files. so far it can write to word.i also want it to be able to navigate a hard disk and open these files using filters.
i was using this code to write to the files
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text, False)
how can i write to pdf and access files and also navigate and open files using openFileDialog?
You should be using System.IO for writting to files. Read the documentation on StreamWriter. It is very straight forward. One of the constructors for streamwriter accepts a string representation of the path to the file, and overloads allow you to specify a FileMode enumeration value. Normally you will use FileMode.OpenOrCreate when writting to the file.
OpenFileDialog is also straightforward. Create an instance and access the selected file property to get a string representation of the path. Use the static File.Exists("path") to check that a valid path was returned, then use the give path to open the file with a StreamReader.
There is more than one way to skin a cat here because static oriented FileInfo and DirectoryInfo are provided in System.IO, and there are the corresponding File and Directory classes which must be instantiated.
The use of these classes is very straightforward so I'm not going to sit here and type you example code but that should get you started.
As far as creating PDF and XLS files, I am assuming that you already have raw bytes that are in the correct format for those file types? If not, I can't help you there off hand. There are no Formatters in the .NET Framework that will convert ASCII or Unicode strings to a format that is acceptable for PDF or XLS that I am aware of. You are going to either need to dig into the specifics of those file formats or find a third party utility that will format your raw bytes or text into something those specifications.
If you are recieving the PDF and XLS data in the raw already properly formatted just use BinaryWriter to create the new file and write the raw array of bytes.