В чем я не прав?
Я попытался скомпилировать код Java, который я нашел в интернете:
javac 1.java
public static void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
try {
OutputStream out = new FileOutputStream(dst);
try {
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} finally {
out.close();
}
} finally {
in.close();
}
У меня есть ошибки:
javac '/1.java'
---------
ERROR in 1.java (at line 1)
public static void copy(File src, File dst) throws IOException {
^^^^
syntax error on token "void", @ expected
---------
ERROR in 1.java (at line 1)
public static void copy(File src, File dst) throws IOException {
^^^^
syntax error on token "File", = expected after this token
---------
ERROR in 1.java (at line 1)
public static void copy(File src, File dst) throws IOException {
^^^^
syntax error on token "File", = expected after this token
---------
ERROR in 1.java (at line 1)
public static void copy(File src, File dst) throws IOException {
^^^^^^
syntax error on token "throws", interface expected
---------
ERROR in 1.java (at line 3)
try {
^^^
syntax error on token "try", delete this token
---------
ERROR in 1.java (at line 15)
} finally {
^^^^^^^
syntax error on token "finally", delete this token
---------
problems (6 errors)
Как исправить эти ошибки?
UPDATE. Что я сделал:
import java.io.*;
//import java.awt.*;
//import java.awt.event.*;
//import javax.swing.*;
//import java.util.*;
//import java.text.*;
//import java.util.regex.*;
class Copy {
public final String dst = "/home/ubuntu/1/1";
public final String src = "/home/ubuntu/assets/ipt.txt";
public static void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
try {
OutputStream out = new FileOutputStream(dst);
try {
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} finally {
out.close();
}
} finally {
in.close();
}
}
}
При компиляции (javac 1.java
) и выполнении (java Copy
) я получаю эту ошибку:
Error: Main method not found in class Copy, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application