Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to take back up .mdb file in java  RSS feed

 
kainil
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guy/Gul .......
I have a some problem of take back up of mdb file i have writen one little java pro. for got the copy of mdb file. It work properly up to copy but my original file is password protected that why when i open new copied file it will not opened. Baz that copied file r correpted but it same as original with byte. So it u have a any idea then help me.
Thanks a lots dear friends.
kkjava

import java.io.*;
import java.io.File;

public class BackUpOfCCMS{

public static void main(String args[])throws Exception{
BufferedReader br = new BufferedReader(new FileReader(new File("D://rnd/ccms.mdb")));
String s = null;
FileWriter fo = new FileWriter("c://backup/ccms.mdb");
while((s = br.readLine()) != null){
fo.write(s);
}
fo.close();
br.close();
System.out.println("Done Succesfully");
}
}

take it this and run it's run properly but when u open the new file it is not allow to open it. before take this code pl. make one ccms.mdb (any access file) with password protected. then go ahead
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kkjava-
Welcome to the JavaRanch! Please adjust your displayed name to meet the JavaRanch Naming Policy. You can do so here.
Thanks! and again, Welcome to the Ranch!
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this will solve your problem, but this is an instance when OutputStreams and InputStreams are superior to Readers and Writers. Readers and Writers assume you are working with text, and may actually change a few things. On the other hand, OutputStreams and InputStreams are designed specifically for working with binary data -- like an mdb file.
Try replacing the middle of the file with this:
 
Andrew Babaian
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran this code and it said "Access Denied" to the destination folder. How is that posible?
Also when you pass 1024 into this array (right?), what is that doing?
byte[] buffer = new byte[1024];
Is there a way to open the file once it's copied to the destination?
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know about the "Access Denied", but the 1024 is just an arbitrary number. When reading from files or the internet or wherever, you generally read in chunks. BufferedReader.readLine() uses chunks the size of a line. InputStream.read() is just one byte.
The InputStream.read(byte[]) and InputStream.read(byte[], int off, int len) methods allow you to read big chunks (in this case the maximum is the arbitrary 1024). Reading and writing bigger chunks all at once is faster than reading and writing several smaller chunks.
Here is a slower alternative:

1024 is just a kilobyte, nothing special. 1234 would have worked just as well (and depending on the file size and computer's free memory, perhaps better).
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kainil -
You are still in violation of the Naming Policy. You must have a first name, a space, and a last name. Please change your display name, or you account will be locked out.
Jason
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!