Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How to write to an InputStream?

write to stream

  • Please log in to reply
6 replies to this topic

#1 tomitzel

tomitzel

    CC Regular

  • Just Joined
  • PipPipPip
  • 44 posts

Posted 19 December 2008 - 03:30 AM

Hello,
My problem is that I have an InputStream from which I read data, modify it and then I want to write it back to the same file. The InputStream is given by a method which finds a certain file after its name. I cannot use any File or URL objects because the class will be in a jar file. Thanks!
  • 0

#2 TALucas

TALucas

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 118 posts
  • Programming Language:Java, (Visual) Basic, Visual Basic .NET, Transact-SQL
  • Learning:C++, PHP, ActionScript

Posted 19 December 2008 - 07:44 AM

I'm not sure I understand the question completely, but you should be able to access a file outside of a Jar file just the same as if you were executing the .class file.
  • 0
Your thoughts are the architects of your destiny.

#3 Stu_328

Stu_328

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 92 posts

Posted 19 December 2008 - 08:57 AM

I'm not sure I understand the post properly either, but you can't write to a file with an InputStream.

An InputStream is just that, it inputs a stream of data to your java program.

If your want to output a stream of data to a file, you need an OutputStream.

HTH
  • 0

#4 tomitzel

tomitzel

    CC Regular

  • Just Joined
  • PipPipPip
  • 44 posts

Posted 19 December 2008 - 02:46 PM

So, the file from which I have to read and after to write in it is in a JAR file, which has other files.
  • 0

#5 Stu_328

Stu_328

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 92 posts

Posted 24 December 2008 - 02:38 AM

What sort of file in the JAR file? a class file? You can't just write uncompiled code to class files.

Have a look at the java.util.zip package and here

Reading files from JARs and Getting Started with the JMX
  • 0

#6 TALucas

TALucas

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 118 posts
  • Programming Language:Java, (Visual) Basic, Visual Basic .NET, Transact-SQL
  • Learning:C++, PHP, ActionScript

Posted 24 December 2008 - 07:48 PM

You can put more than .class files inside a Jar file...text files...or really any file you want.

I'm not sure you can write to the compressed file inside the Jar. You might be able to unpack the jar, edit the file you want, then repackage the Jar, but that's a lot of work. What's the purpose of wanting to write to a file inside the Jar?
  • 0
Your thoughts are the architects of your destiny.

#7 Stu_328

Stu_328

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 92 posts

Posted 25 December 2008 - 03:00 AM

JAR files are just ZIP files glorified by Sun. Use the java.util.zip to work with them.

java.util.zip (Java 2 Platform SE 5.0)
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download