Member Avatar for Illidanek

So in class we are making a program and we have a big problem with what is pretty much the last method we need. We want a download function, which basically takes a file already specified and copies it to the destination (and name) chosen by the user.

WE have a file chooser which allows the user to do that but unfortunately we are having a big problem with the method that would actually copy the mp3 sound. I have looked this up and i know that there is the filecopy method for this, and i tried it and seemed to work fine.

The sound file copied to where it was supposed to copy and everything, it played, but the sound it played was completely messed up.

SO i'm wondering if anyone else has had this problem and if they maybe know how to solve this, if u guys have any idead please help, or maybe there is another way around this?

Thx

Recommended Answers

All 5 Replies

Are you copying from local file or downloading from net?
Your code for that part?

Member Avatar for Illidanek
protected void onDownload()
	{
		FileDialog fileDialog = new FileDialog(this, "Select Download destination", FileDialog.SAVE);
        fileDialog.show();
        if (fileDialog.getFile() != null)
        {
            String directory = fileDialog.getDirectory();
            if (!directory.endsWith(File.separator)) 
            {
                directory += File.separator;
            }
            String file = fileDialog.getFile();
            File input = new File(EditBooks[thenum].getAbook());
            File output = new File(directory + file);
            try
            {
            	copy(input, output);
            }
            catch(IOException e)
            {
            	
            }
        }
	}

private static void copy(File inputFile, File outputFile) throws IOException
	{
		if (checkForExist)
		{
			if (outputFile.exists())
			{
				boolean proceed = false;
				do
				{
					System.out.println("Warning!!! Output file exist. Replace it? Yes(y) / No(n) / Yes to all (a)");
					BufferedReader consoleInput = new BufferedReader(new InputStreamReader(System.in));
					String ans = consoleInput.readLine().toLowerCase();
					if (ans.startsWith("n"))
					{
						System.out.println(inputFile.getName() + " Aborted");
						return;
					}
					if (ans.startsWith("a"))
					{
					checkForExist = false;
					proceed = true;
					}
					if (ans.startsWith("y"))
					{
						proceed = true;
					}
				}
				while(!proceed);
			}
		}
	
	System.out.println(inputFile.getName() + " Copying....");
	FileReader in = new FileReader(inputFile);
	FileWriter out = new FileWriter(outputFile);
	int c;

	while ((c = in.read()) != -1)
	out.write(c);

	in.close();
	out.close();

	System.out.println(inputFile.getName() + " Copied");

	}

The onDownload method is what runs when the download button is pressed, and EditBooks[thenum].getAbook() calls up the path and name of the file that is to be copied.

A lot of error checking going on but it copies the file at line 63.

Member Avatar for Illidanek

THANK YOU soo much dude. That first link was the method we needed :)
I just tested it and works perfectly. I hope it does if it doesn't i hope u'll be around :)


Thank you so much again, thats all the methods in our program working :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.