我怎么了?
我试图编译在互联网上找到的Java代码:
javac 1.java
handleClickButton = (event,some-unique-id) => {
...
this.setState({
open: {
[some-unique-id]: true
}
});
};
我有错误:
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)
在编译(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
答案 0 :(得分:0)
下面是将其签出的代码:
import java.io.*;
class Copy {
public final static String dst = "/home/ubuntu/1/1";
public final static String src = "/home/ubuntu/assets/ipt.txt";
static File fileSrc=new File(src);
static File fileDst=new File(dst);
public static void main(String[] args) throws IOException {
System.out.println("main");
Copy.copy(fileSrc,fileDst);
}
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();
}
}
}