iam_clint 1,208
Recognized Expert Top Contributor
Hello everyone I'm still learning vb.net and I'm stuck on something. -
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
-
Dim fInfo As New FileInfo("servercache.dat")
-
Dim numBytes As Long = fInfo.Length
-
Dim fStream As New FileStream("servercache.dat", FileMode.Open, FileAccess.Read)
-
Dim br As New BinaryReader(fStream)
-
Dim data As Char() = br.ReadChars(CInt(numBytes))
-
'Dim data As Byte() = br.ReadBytes(CInt(numBytes))
-
Dim test As String = ""
-
For i = 0 To 5000
-
test += Convert.ToString(data(i))
-
Next
-
MsgBox(test)
-
-
br.Close()
-
fStream.Close()
-
End Sub
-
This is how I attempted it but i keep just getting one little square...
I attached the dat file zipped up, its from a game called call of duty 4 and its a server list cache. Any ideas or direction would be very helpful thanks.
2 10388 phvfl 173
Recognized Expert New Member
When reading file content I tend to use the following: - Dim contents As New StringBuilder()
-
Dim enc As Encoding = New UTF8Encoding()
-
-
Using fStream As FileStream = New FileStream("servercache.dat", FileMode.Open, FileAccess.Read)
-
-
' The maximum bytes to read.
-
Dim toRead As Int32 = 1024 ' 1Kb
-
-
' The buffer for read bytes.
-
Dim buffer(toRead - 1) As Byte
-
-
' The number of bytes that have been read.
-
Dim read As Int32 = fStream.Read(buffer, 0, toRead)
-
-
' While there is any data that has been read
-
Do While read > 0
-
-
' Get the string from the byte array.
-
contents.Append(enc.GetString(buffer, 0, read))
-
-
' Read next batch of data into the buffer.
-
read = fStream.Read(buffer, 0, toRead)
-
Loop
-
-
fStream.Close()
-
End Using
This code assumes an import of the System.Text namespace. The encoding used will be dependant upon the encoding of the file. The instantiation of the enc object could also have been written as: - Dim enc As Encoding = Encoding.UTF8
A couple of items of note are the Using block and the StringBuilder.
The Using block causes the Dispose method of an iDisposable object to be called once that item is out of scope.
The StringBuilder is used instead of a string due to the iterative process of copying the contents of the file. A string is immutable so every time a concatanation is made a new instance of the object is created and the existing instance recreated. A StringBuilder is mutable and so should give better performance, particularly with larger files. To retrieve the string use the ToString() method of the StringBuilder.
iam_clint 1,208
Recognized Expert Top Contributor @phvfl
Thanks for the help.. When I get this built i'll post the resulting code because i can't find anything on parsing this file on google.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Yang Li Ke |
last post by:
Hi guys!
I have some datas that I must check
everytime a visitor comes to my site
What is better to do:
1- Read data from a file
or
2- Read data from a mysql db
Thank you
|
by: ZafT |
last post by:
Thanks in advance for any tips that might get me going in the right
direction.
I am working on a simple exercise for school that is supposed to use read to
read a file (about 10 MB). I am supposed to change the buffer size and see
how this affects the read time. In other words, the buffer is supposed to
limit how much of the file gets read per call, and cause some change in
speed. I am supposed to do the same with fread as well, but...
|
by: cnu |
last post by:
My program generates a log file for every event that happens in the program.
So, I open the file and keep it open till the end. This is how I open the
file for writing:
<CODE>
public CLogHandler()
{
this.m_fsLog = new FileStream(strTodaysLogFile, System.IO.FileMode.Append,
System.IO.FileAccess.Write, System.IO.FileShare.Read);
this.m_swLog = new StreamWriter(this.m_fsLog);
|
by: ESPN Lover |
last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one
way preferred over the other and why? Thanks.
using System;
using System.IO;
class Test
{
public static void Main()
|
by: a |
last post by:
I have a struct to write to a file
struct _structA{
long x;
int y;
float z;
}
struct _structA A;
//file open
write(fd,A,sizeof(_structA));
//file close
| |
by: lovecreatesbea... |
last post by:
The condition at line 31 is added to check if the program finished to
read the whole file. Is it needed and correct? Thank you.
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int read(string filename, int last_pos)
{
|
by: lovecarole |
last post by:
hi, i am the student who should write a program about reading wav file and do the DFT.
actually i don't know how to read data of the wav song and save it into the array...
if i want to read 17640 every times., and i set byte read=new byte,
i have the wav format paper, but i don't know how to read the data correctly into the byte array, and used for doing DFT....
here's my code, and i am little hurry...thanks for the helps first~
|
by: Thomas Kowalski |
last post by:
Hi,
currently I am reading a huge (about 10-100 MB) text-file line by line
using
fstreams and getline. I wonder whether there is a faster way to read a
file line by line (with std::string line). Is there some way to burst
read the whole file and later "extract" each line?
Thanks in advance,
Thomas Kowalski
|
by: flebber |
last post by:
I was working at creating a simple program that would read the content
of a playlist file( in this case *.k3b") and write it out . the
compressed "*.k3b" file has two file and the one I was trying to read
was maindata.xml . I cannot however seem to use the gzip module
correctly. Have tried the program 2 ways for no success, any ideas
would be appreciated.
Attempt 1
#!/usr/bin/python
|
by: Kevin Ar18 |
last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230
I have a zip file that is several GB in size, and one of the files inside of it is several GB in size. When it comes time to read the 5+GB file from inside the zip file, it fails with the following error:
File "...\zipfile.py", line 491, in read bytes = self.fp.read(zinfo.compress_size)
OverflowError: long it too large to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |