Last active
April 29, 2020 06:44
-
-
Save kirmartuk/bfb08e8ecf00a0d13db81e57a63bbf44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.FileOutputStream; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.net.URL; | |
import java.nio.channels.Channels; | |
import java.nio.channels.ReadableByteChannel; | |
public class sample { | |
public static ReadableByteChannel rbc; | |
public static URL website; | |
public static void main(String[] args) throws IOException { | |
String path = "your save path"; | |
BufferedReader br = new BufferedReader(new FileReader("path to file where located urls")); | |
try { | |
String line = br.readLine(); | |
int i = 150; | |
while (line != null) { | |
String name = line.substring(line.indexOf(",") + 1); | |
line = br.readLine(); | |
website = new URL(line); | |
i++; | |
if (connection()) { | |
FileOutputStream fos = new FileOutputStream(path + name + ".mp3"); | |
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | |
System.out.println(i + " >>ok"); | |
} else | |
System.out.println(i + " >>error"); | |
line = br.readLine(); | |
} | |
} finally { | |
br.close(); | |
} | |
} | |
public static boolean connection() { | |
try { | |
rbc = Channels.newChannel(website.openStream()); | |
return true; | |
} catch (IOException e) { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment