简体   繁体   English

如何从 java 文件中复制 java 代码而不弄乱格式?

[英]How do you copy java code from a java file from eclipse without messing up the format?

I have been trying to copy code from my eclipse program so I can email it to someone that I'm working with, but the format is messed up.我一直在尝试从我的 eclipse 程序中复制代码,以便我可以将 email 代码复制给与我一起工作的人,但格式混乱了。 This is what I want it to look like:这就是我想要的样子:

while (insOrDel) {// Asks the user for five different options:
            // add a username or bot
            // add a special username or bot
            // remove a username or bot
            // remove a special username or bot.
            // list all special usernames or bots.
            // list all usernames or bots
            // run weblog sifter.

However, it ends up like this when it comes out of the email:然而,当它从 email 中出来时,结果是这样的:


        while (insOrDel) {// Asks the user for five different options:
// add a username or bot
// add a special username or bot
// remove a username or bot
// remove a special username or bot.
// list all special usernames or bots.
// list all usernames or bots
// run weblog sifter.

Keep in mind this is after Ctrl+Shift+F, and for some reason, the comments aren't indented.请记住,这是在 Ctrl+Shift+F 之后,并且由于某种原因,注释没有缩进。 Is there a way to fix this?有没有办法来解决这个问题?

Thanks!谢谢!

This can happen when source file uses Tab characters and the destination app you pasting your code in has a different tabwidth.当源文件使用制表符并且您粘贴代码的目标应用程序具有不同的制表符宽度时,可能会发生这种情况。

To avoid this you can set in Eclipse / Window / Preferences / General / Editors / Text Editors the option 'Insert spaces for tabs'为避免这种情况,您可以在 Eclipse / Window / Preferences / General / Editors / Text Editors中设置选项“为制表符插入空格”

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

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