我尝试编译一个java程序,但在代码的导入部分失败:
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.*;
import java.awt.*;
//import java.awt.image.*;
import java.awt.event.*;
//import java.awt.image.renderable.*;
import javax.swing.*;
import javax.swing.border.*;
//import javax.swing.border.EtchedBorder;
//import javax.media.jai.*;
//import javax.media.jai.operator.*;
//import com.sun.media.jai.codec.*;
//import java.lang.reflect.*;
Run Code Online (Sandbox Code Playgroud)
我该如何解决linux debian机器中的问题?谢谢
Java Compiler Compiler Version 4.1d1 (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file SAVE.JSigpac.java . . .
org.javacc.parser.ParseException: Encountered " "import" "import "" at line 443, column 1. Was expecting: "PARSER_BEGIN" ...
Detected 1 errors and 0 warnings.
Run Code Online (Sandbox Code Playgroud) 我正在使用AESCrypt开源库来加密文件.这是我的代码
String password="asdfgh";
String frompath=new String("C:/Users/sabertooth/Desktop/error/pnberror.png");
String topath=new String("C:/Users/sabertooth/desktop/error/");
AESCrypt aes=new AESCrypt(false,password);
aes.encrypt(2, frompath, topath);
Run Code Online (Sandbox Code Playgroud)
我是geeting访问被拒绝的例外.这是堆栈跟踪
Exception in thread "main" java.io.FileNotFoundException: C:\Users\sabertooth\desktop\error (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at java.io.FileOutputStream.<init>(FileOutputStream.java:104)
at AESCrypt.encrypt(AESCrypt.java:284)
at NewClass.main(NewClass.java:28)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Run Code Online (Sandbox Code Playgroud)
发布aescrypt.java的代码
/*
* Copyright 2008 Vócali Sistemas Inteligentes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may …Run Code Online (Sandbox Code Playgroud) 那么文件"MyStore.obj"和我下载的表一起附上了.我应该阅读这个文件的内容,这是与内容的顺序给出的.我可以确定它是否存在?因为你可以看到我尝试使用方法exists()但它没有用
import java.io.*;
public class sheet{
public static void main(String[]args){
try{
FileInputStream fis=new FileInputStream("MyStore.obj");
if(("MyStore.obj").exists()==false) //what can i do to fix this?
throw new FileNotFoundException("file doesn't exist");
ObjectInputStream ois=new ObjectInputStream(fis);
int numOfStorageDevice=ois.readInt();
int numOfComputerGames=ois.readInt();
StorageDevice [] sd=new StorageDevice[numOfStorageDevice];
for(int n=0;n<numOfStorageDevice;n++)
sd[n]=(StorageDevice)ois.readObject();
ComputerGame []cg=new ComputerGame[numOfComputerGames];
for(int m=0;m<numOfComputerGames;m++)
cg[m]=(ComputerGame)ois.readObject();
File file=new File("Result.txt");
FileOutputStream fos=new FileOutputStream(file);
PrintWriter pr=new PrintWriter(fos);
for(int i=0;i<numOfStorageDevice;i++){
String model= sd[i].getmodel();
/*and in the methodcall sd[i].getmodel() it keeps telling that
the symbol cannot be found but i'm sure that the …Run Code Online (Sandbox Code Playgroud) 我曾使用此代码打开文件
Context context = ...;
AssetManager assManager = context.getAssets();
InputStream is = assManager.open("test.crt");
Run Code Online (Sandbox Code Playgroud)
但我想使用该文件写入文件输入流
InputStream caInput = new BufferedInputStream(new FileInputStream("test.crt"));
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助
所以,你可以通过几种方法保存表单文件,我猜,我使用2,但我真的不知道何时使用哪个.我有两个相同的代码:
1 - 这将我的表单文件写入指定的路径.
FormFile archivo = myForm.getArchivo();
File newFile = new File(path, archivo.getFileName());
FileOutputStream fos = new FileOutputStream(newFile);
fos.write(archivo.getFileData());
fos.flush();
fos.close();
Run Code Online (Sandbox Code Playgroud)
2 - 这也是.
FormFile archivo = myForm.getArchivo();
InputStream in = archivo.getInputStream();
OutputStream bos = new FileOutputStream(path + "archivo.ext");
int byteRead = 0;
byte[] buffer = new byte[8192];
while ((byteRead = in.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, byteRead);
}
bos.close();
in.close();
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是,它们中的两个之间有什么区别,我何时应该使用哪个?
我有这个文件:
Line1.
Line2.
Line3.
Line4.
Run Code Online (Sandbox Code Playgroud)
我想从第二行(Line2)开始阅读,直到文件结束.我怎么能用Java做到这一点?
对不起,标题含糊不清.我所拥有的是一个基本上接受用户输入然后将其打印到文件的程序.很简单.输入包括备忘录标题和随后将在该标题下提交的备忘录.两者之间会有一个日期戳.
我打印文件的代码如下所示:
System.out.println("Memo topic (enter -1 to end):");
String message = console.nextLine();
now = new Date();
String dateStamp = now.toString();
out.println(topic + "\n" + dateStamp + "\n" + message);
Run Code Online (Sandbox Code Playgroud)
out是我之前在程序中创建的PrintWriter的名称.控制台显示指令并获取输入,然后将其写入文件.当我读取文件中的文本时,它们一起运行,看起来像这样:
ThanksgivingWed Nov 4 14:39:36 CST"Pick up some turkey at the Kroger, you
lazy bum!" said Mom.
Run Code Online (Sandbox Code Playgroud)
但是,如果我将输出更改为仅打印到控制台,则换行符实际上有效,输出字符串的三个部分按行分割.如何将其修改为正确输出到文件?
当我保存文件时,我使用:
File file = new File(filename);
Run Code Online (Sandbox Code Playgroud)
但是,由于我不再具有写入文件夹的权限,我宁愿将其保存到内存中,然后将文件读取到 FileOutputStream。
我读过我可以用这种方法将文件保存到内存中:
new ByteArrayOutputStream();
Run Code Online (Sandbox Code Playgroud)
整个代码会是什么样子?上传完成后我不知道如何正确编写它。
编辑:我正在使用 Vaadins 上传插件:
public File file;
public OutputStream receiveUpload(String filename,
String mimeType) {
// Create upload stream
FileOutputStream fos = null; // Stream to write to
file = null;
if(StringUtils.containsIgnoreCase(filename, ".csv")){
try {
file = new File(filename);
fos = new FileOutputStream(file);
} catch (final java.io.FileNotFoundException e) {
new Notification("Error", e.getMessage(), Notification.Type.WARNING_MESSAGE)
.show(Page.getCurrent());
return null;
}
} else {
new Notification("Document is not .csv file", Notification.Type.WARNING_MESSAGE)
.show(Page.getCurrent());
return …Run Code Online (Sandbox Code Playgroud) File file = new File("download.png");
File newfile = new File("D:\\Java.png");
BufferedReader br=null;
BufferedWriter bw=null;
try {
FileReader fr = new FileReader(file);
FileWriter fw = new FileWriter(newfile);
br = new BufferedReader(fr);
bw = new BufferedWriter(fw);
char[] buf = new char[1024];
int bytesRead;
while ((bytesRead = br.read(buf)) > 0) {
bw.write(buf, 0, bytesRead);
}
bw.flush();
}
catch (Exception e) {
e.printStackTrace();
} finally {
try {
br.close();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题.是否可以使用BufferedReader和Writer Class?我知道如何使用InputStream和OutputStream制作图像副本,所以不要使用它来粘贴解决方案!
我试图弄清楚如何将所有 System.out.println 存储到一个字符串列表中,就像在任何时候调用 System.out.println 一样,它将被存储为 List 的一个元素。
我已经知道我们可以使用 System.setOut() 捕获 System.out.print。
先感谢您。
java-io ×10
java ×9
file ×2
android ×1
compilation ×1
javacc ×1
method-call ×1
outputstream ×1
printwriter ×1
vaadin ×1