利用 Java 檢查檔案或目錄的大小 (Use Java to check size of a file or a directory)

import java.io.File

public static long filesize(File file){    long size = 0L;    if (file.isFile()){        size = file.length();    } else if (file.isDirectory()){        File[] nFiles = file.listFiles();        for (File nFile : nFiles){            size += filesize(nFile);        }    }    return size;}

自訂的 Java File 排序 (Sort the File class in Java)

import java.util.Comparator;import java.io.File;

public class FileComparator implements Comparator{    public static final int NAME = 1;    public static final int SIZE = 2;    public static final int TYPE = 3;    public static final int MODIFY = 4;    public static final char ASCENDING = 'A';    public static final char DESCENDING = 'D';    private int method;    private char order;    public FileComparator(){        this.setMethod(FileComparator.NAME);        this.setOrder
                    
                
                
                    
                
            
            
            

利用 Java 複製與删除檔案及目錄 (Use Java to copy and delete a file or a directory)

import java.io.File;import java.io.IOException;import java.io.FileNotFoundException;import java.io.FileInputStream;import java.io.FileOutputStream;import java.util.Arrays;

public static void copy(File source, File destination) throws IOException, FileNotFoundException{    if (source. exists() && !source.equals(destination)){        if (source.isFile()){            FileInputStream fis = new FileInputStream(source);            FileOutputStream fos = new FileOutputStream(

Java 的 Internationalization 與 Localization (Internationalization and Localization in Java)

在 Test.java 中編寫
Create a file call Test.java and type

import java.util.ResourceBundle;import java.util.Locale;public class Test {    public static void main(String[] args){        System.out.println(ResourceBundle.getBundle("messages").getString("greetings"));        System.out.println(ResourceBundle.getBundle("messages", new Locale("a", "b")).getString("greetings"

於 Ubuntu 安裝 Google Earth (Install Google Earth in Ubuntu)

前往 https://earth.google.com/
Visit https://earth.google.com/

選擇語言後按 "下載Google地球"
Select the language and click "Download Google Earth"

選擇版本後按 "同意並下載"
Select the version and click "Accept"

下載 .bin 檔案後開啟 Terminal
輸入以下指令
Download .bin file and open the Terminal
Enter the command below
cd "/home/

利用 Java 以不同形狀合併圖像 (Use Java to combine 2 images with a shape of area)

import java.awt.image.BufferedImage;import java.awt.Graphics2D;import java.awt.geom.Ellipse2D;

public static BufferedImage combineEllipse(BufferedImage source, BufferedImage other, int x, int y, int ox, int oy, int owidth, int oheight, int cx, int cy){    BufferedImage out = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());    Graphics2D g2d = out.createGraphics
apple.jpg
Continue reading...

利用 Java 以不同形狀剪裁圖像 (Use Java to cut a shape of area from an image)

import java.awt.image.BufferedImage;import java.awt.Graphics2D;import java.awt.Color;import java.awt.Polygon;import java.awt.Rectangle;import java.awt.geom.Ellipse2D;

public static BufferedImage cutEllipse(BufferedImage source, int x, int y, int width, int height, int cx, int cy, Color color){    BufferedImage out = new BufferedImage(width, height, source.getType());    Graphics2D
apple.jpg
Continue reading...

利用 Java 反轉圖片 (Use Java to reverse an image)

import java.awt.image.BufferedImage;

public static BufferedImage verticalReverse(BufferedImage source){    BufferedImage out = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());    for (int i = 0; i < source.getWidth(); i++){        for (int j = 0; j < source.getHeight(); j++){            out.setRGB(i, j, source.getRGB(i, source.getWidth
apple.jpg
Continue reading...

利用 Java 旋轉圖片 (Use Java to rotate an image)

import java.awt.image.BufferedImage;import java.awt.Graphics2D;import java.awt.Color;import java.awt.geom.AffineTransform;

public static BufferedImage rotate(BufferedImage source, double degrees, int x, int y, Color color, boolean resizable){    double radians = Math.toRadians((degrees % 360.0 + 360.0) % 360.0);    int width = source.getWidth();    int height =
apple.jpg
Continue reading...

利用 Java 將圖像合併 (Use Java to combine 2 images)

import java.awt.image.BufferedImage;import java.awt.Graphics2D;

public static BufferedImage combine(BufferedImage source, BufferedImage other, int x, int y, int ox, int oy, int owidth, int oheight, int cx, int cy){    BufferedImage out = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());    Graphics2D g2d = out.createGraphics();    g2d.drawImage(source,
apple.jpg
Continue reading...