如何从txt文件中读取以下信息,并使用Java将数字只写入另一个文本文件?我让它显示在控制台上,但它也不会写入文件。
琼斯369218658389641
史密斯6011781008881301
韦恩5551066751345482
葡萄酒4809134775860430
大9925689541232325
卢克7586425896325410
白兰地4388576018410707
瑞安2458912425860439
import java.util.Scanner;
import java.io.File;
public class test {
public static vo
我的程序应该在一个文本文件上写入100个随机整数,然后读取它们。问题是我只打印了1个整数。我知道我已经很接近了。我做错了什么?
import java.util.Random;
public class WriteData {
public static void main(String[] args) throws Exception {
//create a file instance
java.io.File file = new java.io.File("random100.txt");
if (fil
我正在尝试使用端口为2649的ServerSocket,但其他人无法连接。它与localhost一起工作得很好。这是人们在尝试连接时得到的错误:
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at j
public void unZipFile(String zipFileLocation, String outputFolder) {
logger.info("ZipFileLocation: "+zipFileLocation);
logger.info("OutputLocation: "+outputFolder);
File dir = new File(outputFolder);
// create output directory if it doesn't exist
if(!dir.exis
我对套接字编程很陌生。我做了一个简单的程序来传输压缩文件,但这只是创建一个空的压缩,不传输任何文件。你能帮帮我吗?
Client.java
package fileTransfer;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
public class SimpleClient {
public final static int SO
这是一个类/方法,它管理正在写入和读取的文件。我有很多代码,当我试图让它正常工作时,代码就会增加。是否有更好的方法来写这个(即修剪脂肪),或者它写得正确?
import java.io.*;
public class DataBase {
public static String getExtension(File f) {
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length
我使用RMI和套接字在客户机集之间传输文件。问题是,当运行下面的代码时,有时我会在客户端得到这样的异常:
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2671)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3146)
at java.io.ObjectInputStream.readStreamHeader(ObjectI
我的任务是通过socket发送文件。我在提示要发送多少文件。但它总是抛出exception。
以下是代码:
public void soc_server() throws IOException {
servsock = new ServerSocket(55000);
sock = servsock.accept();
System.out.println("Hello Server");
Scanner sc = new Scanner(System.in);
**System.out.println("how many fi
我正在尝试将压缩数据写入一个文件,然后使用GZIP库读取数据并解压缩。我已经尝试将所有格式更改为StandardCharsets.UTF-8和ISO-8859-1,但都没有修复GZIP格式错误。我想知道这是否可能与我正在读取的文件有关?下面是压缩函数:
public static byte[] compress(String originalFile, String compressFile) throws IOException {
// read in data from text file
// The name of the file to open.
Str
我不明白什么时候应该使用FileReader和BufferedReader的组合,什么时候使用FileInputStream读取文件(并输出到日志)?
/**
* Created by mona on 3/26/16.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
public class FileExample {
public static
如何在压缩文件中创建压缩包
出现以下错误:
D:\sagar\my work\Package Maker\DirectoryStruct>java zipStructure
java.io.FileNotFoundException: Additional_Sub_Folder\Additional_file.zip (The sy
stem cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.
我有以下WebDriver代码,用于将文件夹/目录压缩为.zip:
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.io.Zip;
public class ZipDir {
public static void main(String... args){
Zip zip = new Zip();
try {
zip.zip(new File("D:\\TmpFS"), new File("D:\\Tm
我有一个使用Sender类的服务器和一个使用下面Downloader类的客户端。当客户端连接到服务器时,它会完美地下载database.db和default.docx,但当它开始读取.png文件时,它会抛出以下错误:
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
at java.io.BufferedInputStream.read(BufferedInputStream.java:308)
at java.io.DataI
我刚开始使用Murach的se6中的一个例子做文件I/O和from。这是我的代码。我是不是错过了什么。我知道后面的代码还有更多,但由于这只是一个示例,所以应该可以工作,对吧?
//Import import java.io.*; for use with the File I/O Methods.
import java.io.*;
public class MainApp
{
public static void main(String[] args)
{
//Create a file object.
File productFile = new Fi
我正在编写一个程序来接收一个文件并输出一个文件。输入文件包含如下内容:
1 cat dog rabbit
3 cat dog rabbit rabbit rabbit
2 yellow red blue white black
0 three two one
输出文件是:
dog rabbit rabbit rabbit blue white black three two one
(程序在每一行的开头输入整数,然后跳过每行中的字数,然后保存剩下的单词并输出到文件中)
一开始,我
import java.util.Scanner;
import java
我已经创建了一个应用程序,其中一个设备必须发送2个txt文件到另一个设备。
客户端代码片段(发送代码):
downloadButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startDownload();
setReceivedFileFromServer("1.Received file from server with success...");
setSendFi