IDEA Practical Tips (Scratch files (temporary files))

When you use IDEA to write project code, have you encountered any of the following situations?

1. To communicate with others, you need to abbreviate the pseudocode of a certain function

2. I want to record some data in json format, and it can be formatted, that is, JSON document function

3. Want to record codes in other languages ​​such as HTML, CSS, SQL, XML, etc.

4. I suddenly have an idea for another project, and I want to record the code so that it can be used when switching to another project

5. Temporarily record HTTP Client call records

6. …

When encountering the above situations, you may need to open other software or editors to operate normally. Switching between different software is troublesome, and if the computer memory is limited, it may cause freezes and affect development efficiency.

IntelliJ IDEA has a function to meet the above requirements, it is Scratch files, temporary file function.

what is scratch file

When we need to create and record some temporary comments or codes outside the context of the current development project, we can use Scratch files and Scratch buffers. Through it, we can avoid frequent switching between multiple programs. Because temporary files are not linked to the project, the temporary files you create in the current project can also be accessed when you open other projects.

Note that because it is a temporary file, it is naturally only stored locally, and must not be used as a multi-person collaboration method; second, the temporary file is not linked to the project, so it is not stored in the project directory, and there is a special place to store them , generally in a certain directory of IDEA under the C drive, you can check the storage location of your temporary files.

Scratch files (temporary files) are fully functional, runnable, and debuggable files that also support syntax highlighting, code completion, and all other features of the corresponding file type.

Because temporary files are not linked to the project and are not stored in the project directory, the temporary files you create in the current project can also be accessed when you open other projects.

Temporary files can be used to write some simple Java code, HTTP requests, JSON documents, etc.

Scratch buffers are simple text files without any coding assistance. It can be used as a simple note recorder, or to record tasks and other functions.

They are also not stored in the project directory, nor can they be accessed and opened from another project. Up to 5 temporary buffers with default names can be created, which can be reused by clearing their contents.

 

How to create temporary files

create scratch file

  • Created via the File menu, File - New - Scratch File.

  • Create through shortcut keys, Ctrl+Alt+Shift+Insert.

Select the corresponding code or content, press Ctrl+Alt+Shift+Insert shortcut key, IDEA will create a file of the corresponding language type according to the content, if it cannot be recognized, it will create a temporary file with the same type and extension as the original content.

 

picture

In the opened file list, we can select the corresponding type of temporary file according to our own situation, as follows:

 

create scratch buffer

There is no special menu item in IDEA to create a new scratch buffer, but we can use Find action (shortcut key Ctrl+Shift+A), and then enter new scratch buffer to create.

picture

 

 

The name of the temporary buffer file created by IntelliJ IDEA is buffer1.txt by default, and the numbers are incremented to buffer5.txt in turn. The upper limit is 5 files. If you continue to create, buffer1.txt will be recreated and you will be asked whether to save the previous records. If you want to save more than 5 files, you can do it by renaming the file names.

characteristic

Support most language files, and syntax highlighting, syntax recognition.

 

 

It can be run and debugged by clicking the icon in the left column.

 

 

Local history, which enables rollback and rewriting of content.

 

 

There are also features such as cross-project access, file renaming, moving, deleting, copying, etc., which you can experience by yourself.

Guess you like

Origin blog.csdn.net/wufaqidong1/article/details/132224277