我正在开发加密工具,对于我们的加密文件格式,我使用Base64来编码数据.我正在使用apache commons编解码器使用围绕FileInputStream的Base64InputStream来解码文件.在我在大型音乐文件上测试之前,这就像一个魅力.出于一些神秘的原因,当我这样做时,字节6028之后的每个字节变为0.将其读入byte []的代码如下:
FileInputStream filein = new FileInputStream(filename);
Base64InputStream in = new Base64InputStream(filein,false,76,'\n');
byte[] contents = new byte[known_and_tested_correct_filelength];
in.read(contents);
Run Code Online (Sandbox Code Playgroud)
现在,无论出于何种原因,在字节6028之后,所有内容contents都是0.但是,contents.length大约是300,000字节.你可以猜到,这对我的应用程序来说确实很奇怪.有没有人知道发生了什么?
我正在尝试修改(扩展)FileInputStream类,以便我可以打开加密文件并将该流用于MediaPlayer setDataSource(FileDescriptor).问题是我不知道应该覆盖哪个方法来在流内进行解密.我尝试覆盖所有read()方法,但mediaPlayer似乎没有使用它们.
有什么建议?
import java.io.*;
import java.util.Properties;
public class NewClass {
public static void main(String args[]) throws IOException {
Properties p = new Properties();
p.load(new FileInputStream("DBDriverInfo.properties"));
String url=p.getProperty("url");
String user=p.getProperty("username");
String pass=p.getProperty("password");
System.out.println(url+"\n"+user+"\n"+pass);
}
}
Run Code Online (Sandbox Code Playgroud)
虽然文件DBDriverInfo.properties文件位于同一目录中,但会引发以下异常.
Exception in thread "main" java.io.FileNotFoundException: DBDriverInfo.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at NewClass.main(NewClass.java:7)
Run Code Online (Sandbox Code Playgroud)
javac在命令行界面中编译时,相对路径工作正常.但NetBeans中的异常引发了异常.
我试图使用FileInputStream基本上读取文本文件,然后将其输出到不同的文本文件中.但是,当我这样做时,我总是会得到非常奇怪的角色.我确信这是我犯的一个简单的错误,感谢任何帮助或指向我正确的方向.这是我到目前为止所得到的.
File sendFile = new File(fileName);
FileInputStream fileIn = new FileInputStream(sendFile);
byte buf[] = new byte[1024];
while(fileIn.read(buf) > 0) {
System.out.println(buf);
}
Run Code Online (Sandbox Code Playgroud)
它正在读取的文件只是一个普通ASCII字符的大文本文件.然而,每当我执行system.out.println时,我得到输出[B @ a422ede.关于如何使这项工作的任何想法?谢谢
老实说,我已经搜索了很多这样的任务,所以我最终尝试了各种方法,但没有任何工作,直到我最终得到这个代码.它完全适合我,所以我不想改变我的代码.
我需要的帮助是将这个代码放在一个开始读取文件的方式,但如果文件不存在,那么它将创建一个新文件.
保存数据的代码:
String data = sharedData.getText().toString();
try {
fos = openFileOutput(FILENAME, MODE_PRIVATE);
fos.write(data.getBytes());
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
加载数据的代码:
FileInputStream fis = null;
String collected = null;
try {
fis = openFileInput(FILENAME);
byte[] dataArray = new byte [fis.available()];
while (fis.read(dataArray) != -1){
collected = new String(dataArray);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally …Run Code Online (Sandbox Code Playgroud) 我正在尝试练习从 Java 文件中读取文本。我不太了解如何读取 N 行,比如文件中的前 10 行,然后将这些行添加到ArrayList.
例如,文件包含 1-100 个数字,如下所示;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- ....
Run Code Online (Sandbox Code Playgroud)
我想读取前 5 个数字,即 1,2,3,4,5 并将其添加到数组列表中。到目前为止,这是我设法做的,但我被卡住了,不知道现在该做什么。
ArrayList<Double> array = new ArrayList<Double>();
InputStream list = new BufferedInputStream(new FileInputStream("numbers.txt"));
for (double i = 0; i <= 5; ++i) {
// I know I need to add something here so the for loop read through
// the file but I …Run Code Online (Sandbox Code Playgroud) 我是新的yii2,所以我有这个问题.我想使用fileinput所以我添加fileinput这个网址 http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html 如果我用文件输入创建新模型(选择视频),如果我删除模型中的项目:**Ber Request(#400)无法验证您的数据提交.如果我选择图像,它可以正常工作如何在yii2上传视频?
我的日志:
exception 'yii\web\BadRequestHttpException' with message 'Unable to verify your data submission.' in C:\xampp\htdocs\project\vendor\yiisoft\yii2\web\Controller.php:110
Stack trace:
C:\xampp\htdocs\project\vendor\yiisoft\yii2\base\Controller.php(149): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
C:\xampp\htdocs\project\vendor\yiisoft\yii2\base\Module.php(455): yii\base\Controller->runAction('delete', Array)
C:\xampp\htdocs\project\vendor\yiisoft\yii2\web\Application.php(84): yii\base\Module->runAction('music/delete', Array)
C:\xampp\htdocs\project\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
C:\xampp\htdocs\project\web\index.php(12): yii\base\Application->run()
{main}
Run Code Online (Sandbox Code Playgroud)
请帮我?谢谢 !
fileinputstream yii-extensions yii2 yii2-advanced-app yii2-basic-app
我想使用FileStream在Java中复制文件.这是我的代码.
FileInputStream infile = new FileInputStream("in");
FileOutputStream outfile = new FileOutputStream("out");
byte[] b = new byte[1024];
while(infile.read(b, 0, 1024) > 0){
outfile.write(b);
}
infile.close();
outfile.close();
Run Code Online (Sandbox Code Playgroud)
我使用vim来查看我的文件.
输入文件"in"
Hello World1
Hello World2
Hello World3
Run Code Online (Sandbox Code Playgroud)
输出文件"输出"
Hello World1
Hello World2
Hello World3
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@...
Run Code Online (Sandbox Code Playgroud)
输出文件中有许多额外的'^ @'.
输入文件的大小为39字节.
输出文件的大小为1KB.
为什么输出文件中有很多额外的字符?
我想将 FileOutputStream 转换为 Byte 数组,以便在两个应用程序之间传递二进制数据。请问有人可以帮忙吗?
是否可以获得Filea 正在使用的信息FileInputStream?FileInputStream似乎没有任何方法可以检索它。
fileinputstream ×10
java ×6
android ×3
bytearray ×2
file ×2
arraylist ×1
base64 ×1
file-io ×1
for-loop ×1
java-io ×1
media-player ×1
netbeans ×1
netbeans-7 ×1
properties ×1
yii2 ×1