简体   繁体   English

java中的文件输入输出

[英]File input and output in java

I am beginner of java.我是java初学者。

i am trying a write and show file.我正在尝试写入和显示文件。

But my txt file show another symbol.但是我的 txt 文件显示了另一个符号。

I can not understand what my Error.我不明白我的错误是什么。

I am using this code.我正在使用此代码。

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


public class Main {

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub

        try {
            FileOutputStream output=new FileOutputStream("C:\\Users\\BAPPY\\Desktop\\temp.txt");
            for (int i = 0; i <=10; i++) {
                output.write(i);
            }
            output.close();

            FileInputStream input=new FileInputStream("C:\\Users\\BAPPY\\Desktop\\temp.txt");
            int value;
            while ((value=input.read())!=-1) {
                System.out.println(value+" ");
            }
            input.close();


        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

}

my txt file did not show result why please tell me??我的txt文件没有显示结果为什么请告诉我??

I think that your code is working the problem is that you are not seeing anything cause what you are writing are not understandable symbols.我认为您的代码正在工作,问题在于您没有看到任何东西,因为您正在编写的不是可理解的符号。

Change for (int i = 0; i <=10; i++) { output.write(i);更改为 (int i = 0; i <=10; i++) { output.write(i); } }

for为了

        for (int i = 66; i <=127; i++) {
            output.write(i);
        }

and tell how it goes.并告诉它是怎么回事。

I hope it helps我希望它有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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