0

in my project, I am opening text files, and im doing some changes to the files, and I want to save the file after im chaning it, like Save As with a location browse. Can I do it somehow?

Thanks for the help!

Golan Kiviti
  • 3,895
  • 7
  • 38
  • 63

3 Answers3

0

Here is a link that should help you: Binary streams

Or you can maybe try this: Reading/writing text files

user2919688
  • 5
  • 1
  • 3
0

A little search over the internet will help. Here;s a basic program that will read from one file and write to other. You can modify as per your requirement.

import java.io.*;

public class CopyFile {
   public static void main(String args[]) throws IOException
   {
      FileInputStream in = null;
      FileOutputStream out = null;

      try {
         in = new FileInputStream("input.txt");
         out = new FileOutputStream("output.txt");

         int c;
         while ((c = in.read()) != -1) {
            out.write(c);
         }
      }finally {
         if (in != null) {
            in.close();
         }
         if (out != null) {
            out.close();
         }
      }
   }
}

Some more tutorials here:

Pramod Karandikar
  • 5,289
  • 7
  • 43
  • 68
0

You should offer some code. However, yes by Using e.g. FileWriter you just open your File with FileWriter(File file, boolean append=true) and call close() when your done. Saving is automatic so to say.

user2504380
  • 535
  • 4
  • 12