java获取mp3封⾯_java如何获取.mp3格式⽂件内置歌曲封⾯展开全部
封⾯就是图⽚,62616964757a686964616fe59b9ee7ad9431333337616466⽤java的类抓取图⽚即可package tool;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.HttpURLConnection;
import java.URL;
import java.util.LinkedList;
import java.util.List;
import Matcher;
import Pattern;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import Style;
import StyleConstants;
import StyleContext;
import StyledDocument;
public class ImageViewer extends JFrame
{
private static final String DOWNLOADPATH = "download/";
JTextPane textPane = new JTextPane ();
LinkedList initString = new LinkedList ();
LinkedList initStyles = new LinkedList ();
LinkedList path = new LinkedList ();
public ImageViewer ()
{
setTitle ("图⽚预览下载器 v1.0");
setLayout (new BorderLayout ());
setSize (500, 300);
setLocationRelativeTo (null);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
private void addComponents ()
{
final JTextField urltField = new JTextField ();
JPanel right = new JPanel (new FlowLayout (FlowLayout.RIGHT, 0, 0));
final JButton go = new JButton ("GO");
textPane.setEditable (false);
JScrollPane content = new JScrollPane (textPane);
go.addActionListener (new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
String url = Text ().trim ();
resolveHTML (url, "utf8", "(?i)\\]*src[\\=\\s\'\"]+([^\\>\'\"]+)[\'\"]?[^\\>]*\\>"); }
});
JPanel up = new JPanel (new BorderLayout ());
up.add (urltField, BorderLayout.CENTER);
right.add (go);
JButton download = new JButton ("DOWNLOAD");
{
@Override
public void actionPerformed ( ActionEvent e )
{
downloadImages ();
}
});
right.add (download);
up.add (right, BorderLayout.EAST);
add (up, BorderLayout.NORTH);
add (content, BorderLayout.CENTER);
}
private void downloadImages ()
{
File fp = new File (DOWNLOADPATH);
if (!fp.exists ())
{
fp.mkdir ();
}
for ( int i = 0; i
{
try
{
String p = (i);
URL url = new URL (p);
HttpURLConnection huc = (HttpURLConnection) url.openConnection (); huc.setRequestMethod ("GET");
huc.setConnectTimeout (5 * 1000);
InputStream is = InputStream ();
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
byte[] buffer = new byte[1024];
int len = -1;
while (( len = is.read (buffer) ) != -1)
baos.write (buffer, 0, len);
}
baos.flush ();
baos.close ();
is.close ();
huc.disconnect ();
byte[] data = ByteArray ();
String name = p.substring (p.lastIndexOf ("/") + 1, p.length ());
name = ains (".") ? name : name + ".jpg";
FileOutputStream fos = new FileOutputStream (new File (DOWNLOADPATH + name)); fos.write (data);
fos.flush ();
fos.close ();
}
catch (Exception e)
{
continue;
}
}
}
private void loadImages ( List initString, List initStyles, List url )
{
try
{
StyledDocument doc = StyledDocument ();
addStylesToDocument (doc, url, initStyles);
for ( int i = 0; i
{
doc.insertString (Length (), (i), Style ( (i)));
}
}
catch (Exception e)
}
protected void addStylesToDocument ( StyledDocument doc, List url, List initStyles )
{
Style def = DefaultStyleContext ().getStyle (StyleContext.DEFAULT_STYLE); for ( int i = 0; i
{
Style s = doc.addStyle ( (i), def);
StyleConstants.setAlignment (s, StyleConstants.ALIGN_CENTER);
ImageIcon icon = createImageIcon ( (i));
if (icon != null)
{
StyleConstants.setIcon (s, icon);
}
}
如何下载mp3歌曲}
protected static ImageIcon createImageIcon ( String url )
{
URL imgURL = null;
try
{
imgURL = new URL (url);
if (imgURL != null)
{
return new ImageIcon (imgURL);
}
}
catch (Exception e)
{}
return null;
}
private void resolveHTML ( String spec, String charsetName, String regex )
{
try
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论