user979150
user979150

Reputation: 359

Importing Java libraries into C#

So, I have written my code to .zip files in C#, but when I import the libraries I have the following:

Using java.util;
Using java.util.zip;
Using java.io;

But, these are underlined in red, with the error message, The type or namespace "java" could not be found

Is there some reference I need to add?

Upvotes: 3

Views: 23038

Answers (4)

user719662
user719662

Reputation:

Actually, you can. One word - JavApi.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500515

Well unless you're using J# (which became obsolete quite a while ago) you shouldn't be trying to use Java libraries in .NET. You should use the .NET framework libraries instead.

If you want a port of the Java zip libraries to .NET, there's one available at SharpZipLib. That should make it reasonably easy to port your C# code to use the right libraries - but for almost all tasks, you shouldn't be trying to use anything from Java; you should use the idiomatic .NET-based tool which solves the same problem. Sometimes there's a project which shares the same philosophies and possibly original implementation roots (e.g. NHibernate for Hibernate) but sometimes there are completely different options available.

Upvotes: 6

Michael Minton
Michael Minton

Reputation: 4495

There is no way to import an actual Java library into c#. You may want to consider looking at jni4net - "bridge between Java and .NET".

Upvotes: 4

Oded
Oded

Reputation: 499002

You can't import Java libraries directly to .NET.

You should use IKVM if you want to use Java in .NET, though there are zip libraries for .NET - here is one, SharpZipLib.

Additionally, the syntax is using, not Using - it is all lower case.

Upvotes: 11

Related Questions