如何将类写入文本文件 [英] How to write a class to a text file

查看:375
本文介绍了如何将类写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


让我们说我的程序中有一个类作为对象,我想把这个对象写成文本文件而不是一个对象,但作为此文件中的真实文本表示如:


公共类MyClass {

私有类型属性1

.. 。



}

Hi all,

Let''s say that I have a class as an object somewhere in my program and I want to write this object down into a text file but not as an object but as the real text representation in this file like:

public class MyClass {
private type attribute1
...
.
}

推荐答案

你必须亲自获取每一条信息。请参阅有关如何获取数据成员,方法等的java文档。


不确定是否可以在方法中获取代码。不要以为那是可能的。


你为什么要这样做?你不能只将.java文件保存为其他地方没有用你的程序编译的文本文件吗?


这看起来有点奇怪。



Dan
You have to get every piece of information yourself. See the java docs on how to get the data members, methods, etc.

Not sure if you can get the code inside the methods though. Don''t think that''s possible.

Why do you want to do this? Can''t you just save the .java file as a text file somewhere else not compiled with your program?

This seems kind of like a very strange thing to do.


Dan


我想这是不可能的。对象是一个实时实体,你不能让它代表类声明。


无论如何你想要实现什么?如果你分享你想做什么,我们可以建议一个替代解决方案,如果有的话。


问候,

Dheeraj Joshi
I guess this is not possible. Object is a real time entity, you can not make it to represent the class declaration.

Anyway what are you trying to achieve? If you share what are you trying to do, we can suggest a alternate solution, if there is one.

Regards,
Dheeraj Joshi


反思可以帮到你。


这篇关于如何将类写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆