[-] Menembak Maling.
[-] Menembak Hutang dari Kontrakan/Rental.
Download dan Belajar Software, Download, Script all Programming Dunia IT.
java.net.URL
class, which represents a Uniform Resource Locator. Here's how you can work with URLs in Java:URL
object by providing a string representation of the URL. try {
URL url = new URL("http://www.example.com");
} catch (MalformedURLException e) {
// Handle the exception if the URL is invalid
e.printStackTrace();
}
java.net.URI
to parse or construct a URL instead of the deprecated URL constructors.openConnection()
method of the URL
object, which returns a URLConnection
object. try {
URL url = new URL("http://www.example.com");
URLConnection connection = url.openConnection();
connection.connect(); // Initiates the connection
} catch (MalformedURLException | IOException e) {
e.printStackTrace();
}
getInputStream()
method of the URLConnection
object, which returns an InputStream
. try {
URL url = new URL("http://www.example.com");
URLConnection connection = url.openConnection();
InputStream inputStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
inputStream.close();
} catch (MalformedURLException | IOException e) {
e.printStackTrace();
}
HttpURLConnection
. try {
URL url = new URL("http://www.example.com/api");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET"); // Or "POST"
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
// Read response
}
connection.disconnect();
} catch (MalformedURLException | IOException e) {
e.printStackTrace();
}
setRequestProperty()
and handle the response accordingly.getProtocol()
, getHost()
, getPort()
, and getFile()
.getRef()
.URL
object using the file path. try {
URL fileUrl = new URL("file:///path/to/your/file.txt");
} catch (MalformedURLException e) {
e.printStackTrace();
}
MalformedURLException
when creating URL
objects, and IOException
when connecting to or reading from URLs.import java.awt.*;
import java.awt.print.*;
public class PrintExample implements Printable {
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex > 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) graphics;
g2d.drawString("Hello, Printer!", 100, 100);
return PAGE_EXISTS;
}
public static void main(String[] args) {
PrinterJob printerJob = PrinterJob.getPrinterJob();
PrintService[] services = PrinterJob.lookupPrintServices();
if (services.length > 0) {
try {
printerJob.setPrintService(services[0]);
printerJob.setPrintable(new PrintExample());
if (printerJob.printDialog()) {
printerJob.print();
}
} catch (PrinterException e) {
e.printStackTrace();
}
} else {
System.out.println("No printers found.");
}
}
}
long download1 = net.getBytesRecv();
long timestamp1 = net.getTimeStamp();
Thread.sleep(2000); //Sleep for a bit longer, 2s should cover almost every possible problem
net.updateNetworkStats(); //Updating network stats
long download2 = net.getBytesRecv();
long timestamp2 = net.getTimeStamp();
System.out.println("prova " + (download2 - download1)/(timestamp2 - timestamp1));
//Do the correct calculations
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
public class Progressbar {
public static void main(String[] args) {
final JProgressBar jProgressBar = new JProgressBar();
jProgressBar.setMaximum(100000);
JFrame frame = new JFrame();
frame.setContentPane(jProgressBar);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(300, 70);
frame.setVisible(true);
Runnable updatethread = new Runnable() {
public void run() {
try {
URL url = new URL("http://downloads.sourceforge.net/project/bitcoin/Bitcoin/blockchain/bitcoin_blockchain_170000.zip");
HttpURLConnection httpConnection = (HttpURLConnection) (url.openConnection());
long completeFileSize = httpConnection.getContentLength();
java.io.BufferedInputStream in = new java.io.BufferedInputStream(httpConnection.getInputStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(
"package.zip");
java.io.BufferedOutputStream bout = new BufferedOutputStream(
fos, 1024);
byte[] data = new byte[1024];
long downloadedFileSize = 0;
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
downloadedFileSize += x;
// calculate progress
final int currentProgress = (int) ((((double)downloadedFileSize) / ((double)completeFileSize)) * 100000d);
// update progress bar
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
jProgressBar.setValue(currentProgress);
}
});
bout.write(data, 0, x);
}
bout.close();
in.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
};
new Thread(updatethread).
start();
}
}