简体   繁体   中英

How to write from .data file to .txt file In Java?

I have written some information into a .data file

PrintWriter out;
DataOutputStream binaryFile= null;
public WriteToFile(String file,String text ) throws IOException {

     binaryFile= new DataOutputStream(
                new FileOutputStream(file,true));
     binaryFile.writeInt(2); 
     binaryFile.writeDouble(3);
     binaryFile.writeChar(2);
     binaryFile.writeUTF(text);
     binaryFile.close();  
}

I'm looking for a way to make a function that takes a .data file and writes each and every value into a corresponding text file

So Far I've tried this :

public void writeToTextFile(String myFile)
{
    DataOutputStream fichIn = new DataOutputStream(new FileOutputStream(myFile));;
    try {
        //How to take information from .data file and writethem in text file ? 
    } catch (IOException e) {
        System.out.println("Error");
    }

    // Some Code
}

您需要使用DataInputStream和与您用于编写它的readXXX()方法对应的writeXXX()方法读取二进制文件,然后使用PrintWriter的方法写入新的文本文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM