如何创建自己的文件扩展名,如.odt或.doc? [英] How to create my own file extension like .odt or .doc?

查看:523
本文介绍了如何创建自己的文件扩展名,如.odt或.doc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理像microsoft word(学术项目)这样的文档处理项目。

I am working with a document processing project like microsoft word (Academic project).

有没有快速创建自己的扩展程序的方法。有没有第三方图书馆?

Is there any quick way to create my own extension. Is there any third party library?

推荐答案

文件扩展名只是上一期后文件名的一部分。

A file extension is just the portion of the file name after the last period.

例如在路径中:

C:\ Users \Tests \ My Documents \ file.txt

文件扩展名为 .txt ,通常表示该文件包含文本数据。
要创建自己的文件扩展名,您需要做的就是在文件名中的最后一个句点之后放置所需的扩展名。

The file extension is .txt which typically indicates that the file contains text data. To create your own file extension all you need to do is to place the desired extension after the last period in the filename.

在Java中,您可以创建一个文件使用文件类型的对象,如下所示:

In Java you can create a file using an object of type File like this:

File file = new File("file.txt")

该文件将在当前工作目录中创建,并将扩展名为 txt ,因为这是文件名中最后一个句点之后的值。

The file will be created in the current working directory and will have the extension txt because this is the value after the final period in the file name.

文件格式是指到文件内部的数据布局。创建自定义文件格式包括考虑如何将数据存储在文件中,并以与该布局匹配的方式将其写入文件。

A file format refers to the layout of data inside a file. Creating a custom file format involves thinking about how you want to store your data within the file, and writing it to the file in a way which matches that layout.

例如
如果我有地址簿应用程序我可能会决定存储人员姓名和电话号码,用制表符分隔并将此数据保存在扩展名地址

我的 AddressBook.Save()函数可能看起来像这个Java代码。应该注意的是,我已经用Java编程了很多年并且可能会出错。

My AddressBook.Save() function might look something like this Java code. It should be noted that I haven't programmed in Java for a number of years and mistakes are likely.

void Save(File file)
{
 FileWriter writer = new FileWriter(file);

foreach (AddressBookEntry entry in this.entries)
{
this.SaveEntry(entry,writer);
}
} 


void SaveEntry(AddressBookEntry entry,  FileWriter writer)
{
  String record = entry.getFirstName() + "\t" + entry.getLastName() + "\t" +
  entry.getPhoneNumber();
  writer.write(record, 0, record.length();
}

如果我们有这样的地址条目:

If we had an address entry like this:

First Name:Test
Last Name: Bob
Phone Number=555-1212

然后该条目将出现在中。地址文件如下

Then the entry would appear in the .address file as follows

测试Bob 555-1212

我希望这有助于解释文件扩展名和文件格式之间的区别,并通过自定义扩展程序向您展示如何创建自己的格式。

I hope that's helped explain the difference between a file extension and a file format and has gone some way to showing you how to create your own format, with a custom extension.

这篇关于如何创建自己的文件扩展名,如.odt或.doc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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