3

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?

user979150
  • 339
  • 2
  • 4
  • 6
  • 1
    Have you looked at the answer to this question? http://stackoverflow.com/questions/512124/use-a-jar-java-library-api-in-c – Vala Nov 08 '11 at 14:35

4 Answers4

11

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.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
6

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
4

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".

Michael Minton
  • 4,447
  • 2
  • 19
  • 31
0

Actually, you can. One word - JavApi.