473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Javascript to .Net

I have researched a lot trying to get this. So as a last resource I will
have to ask here.

What would be the equivalent to the following javascript excerpt:

TheDataManager MyDMgr = new TheDataManager();

File MyDataFile = new File(strDataPath);

// Create a new file if and only if it doesn't already exist
boolean mNoFileExists = MyDataFile.createNewFile();

//new file was created
if ( mNoFileExists )
{
// Write out the data to disk using serialization
FileOutputStream fos = new FileOutputStream(MyDataFile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(MyDMgr);
oos.close();
}
Nov 16 '05 #1
4 2168
This isn't JavaScript. It's Java.

Assuming you have the source to TheDataManager class, it should be a pretty
straightforward conversion. What specifically do you have questions about?

--Bob

"Carlitos" <Ca******@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
I have researched a lot trying to get this. So as a last resource I will
have to ask here.

What would be the equivalent to the following javascript excerpt:

TheDataManager MyDMgr = new TheDataManager();

File MyDataFile = new File(strDataPath);

// Create a new file if and only if it doesn't already exist
boolean mNoFileExists = MyDataFile.createNewFile();

//new file was created
if ( mNoFileExists )
{
// Write out the data to disk using serialization
FileOutputStream fos = new FileOutputStream(MyDataFile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(MyDMgr);
oos.close();
}

Nov 16 '05 #2
Oh, geez, sorry. Yes, it is Java. I've been working with programs in both
Java and Javascript, and suddenly I got themmixed up. Sorry about that.

I am translating from Java and Javascript to .Net (don't ask me why, I am
just following orders from my boss) and these lines are giving me a hard
time, though they seem very simple.

Yes, you can safely assume I have the implementation for class
TheDataManager. What I interpret from this Java code is that the programmer
wants to serialize and save to disk a TheDataManager instance class. The
thing is that I am not 100% sure about it, so I don't know exactly what to
do. That's why I have been looking for the "literally equivalent" lines of
codes for the Java lines I posted here.

If you wouldn't mind, how would you write these lines, say in C# or VB.Net?

Thank you very much.

C

"Bob Grommes" wrote:
This isn't JavaScript. It's Java.

Assuming you have the source to TheDataManager class, it should be a pretty
straightforward conversion. What specifically do you have questions about?

--Bob

"Carlitos" <Ca******@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
I have researched a lot trying to get this. So as a last resource I will
have to ask here.

What would be the equivalent to the following javascript excerpt:

TheDataManager MyDMgr = new TheDataManager();

File MyDataFile = new File(strDataPath);

// Create a new file if and only if it doesn't already exist
boolean mNoFileExists = MyDataFile.createNewFile();

//new file was created
if ( mNoFileExists )
{
// Write out the data to disk using serialization
FileOutputStream fos = new FileOutputStream(MyDataFile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(MyDMgr);
oos.close();
}


Nov 16 '05 #3
Carlitos wrote:
What would be the equivalent to the following javascript excerpt:

TheDataManager MyDMgr = new TheDataManager();

File MyDataFile = new File(strDataPath);

// Create a new file if and only if it doesn't already exist
boolean mNoFileExists = MyDataFile.createNewFile();

//new file was created
if ( mNoFileExists )
{
// Write out the data to disk using serialization
FileOutputStream fos = new FileOutputStream(MyDataFile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(MyDMgr);
oos.close();
}


First of all, this is Java and not JavaScript. The conversion to C#
should be straight forward as long as a) you've implemented the
TheDataManager class and b) the serialized files don't have to be
interoperable with the Java implementation.
If these conditions are met the following code should do the trick:

TheDataManager myDMgr=new TheDataManager();

if (!File.Exists(strDataPath)) {
FileStream stream=new FileStream(strDataPath,FileMode.Create);
BinaryFormatter formatter=new BinaryFormatter();
formatter.Serialize(stream, myDMgr);
stream.Close();
}

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 16 '05 #4
Thank you Anders.

As I said in another post of this thread, yes, I realized this was not
Javascript after I posted the message.

Thanks again.

C

"Anders Norås [MCAD]" wrote:
Carlitos wrote:
What would be the equivalent to the following javascript excerpt:

TheDataManager MyDMgr = new TheDataManager();

File MyDataFile = new File(strDataPath);

// Create a new file if and only if it doesn't already exist
boolean mNoFileExists = MyDataFile.createNewFile();

//new file was created
if ( mNoFileExists )
{
// Write out the data to disk using serialization
FileOutputStream fos = new FileOutputStream(MyDataFile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(MyDMgr);
oos.close();
}


First of all, this is Java and not JavaScript. The conversion to C#
should be straight forward as long as a) you've implemented the
TheDataManager class and b) the serialized files don't have to be
interoperable with the Java implementation.
If these conditions are met the following code should do the trick:

TheDataManager myDMgr=new TheDataManager();

if (!File.Exists(strDataPath)) {
FileStream stream=new FileStream(strDataPath,FileMode.Create);
BinaryFormatter formatter=new BinaryFormatter();
formatter.Serialize(stream, myDMgr);
stream.Close();
}

Anders Norås
http://dotnetjunkies.com/weblog/anoras/

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.